!function(t) {
    var e = {};
    function i(s) {
        if (e[s])
            return e[s].exports;
        var l = e[s] = {
            i: s,
            l: !1,
            exports: {}
        };
        return t[s].call(l.exports, l, l.exports, i),
        l.l = !0,
        l.exports
    }
    i.m = t,
    i.c = e,
    i.d = function(t, e, s) {
        i.o(t, e) || Object.defineProperty(t, e, {
            enumerable: !0,
            get: s
        })
    }
    ,
    i.r = function(t) {
        "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
            value: "Module"
        }),
        Object.defineProperty(t, "__esModule", {
            value: !0
        })
    }
    ,
    i.t = function(t, e) {
        if (1 & e && (t = i(t)),
        8 & e)
            return t;
        if (4 & e && "object" == typeof t && t && t.__esModule)
            return t;
        var s = Object.create(null);
        if (i.r(s),
        Object.defineProperty(s, "default", {
            enumerable: !0,
            value: t
        }),
        2 & e && "string" != typeof t)
            for (var l in t)
                i.d(s, l, function(e) {
                    return t[e]
                }
                .bind(null, l));
        return s
    }
    ,
    i.n = function(t) {
        var e = t && t.__esModule ? function() {
            return t.default
        }
        : function() {
            return t
        }
        ;
        return i.d(e, "a", e),
        e
    }
    ,
    i.o = function(t, e) {
        return Object.prototype.hasOwnProperty.call(t, e)
    }
    ,
    i.p = "",
    i(i.s = 1)
}([function(t, e, i) {}
, function(t, e, i) {
    "use strict";
    i.r(e);
    class s {
        constructor(t, e="") {
            "string" == typeof t ? (this.el = document.createElement(t),
            this.el.className = e) : this.el = t,
            this.data = {}
        }
        data(t, e) {
            return void 0 !== e ? (this.data[t] = e,
            this) : this.data[t]
        }
        on(t, e) {
            const [i,...s] = t.split(".");
            let l = i;
            return "mousewheel" === l && /Firefox/i.test(window.navigator.userAgent) && (l = "DOMMouseScroll"),
            this.el.addEventListener(l, t=>{
                e(t);
                for (let e = 0; e < s.length; e += 1) {
                    const i = s[e];
                    if ("left" === i && 0 !== t.button)
                        return;
                    if ("right" === i && 2 !== t.button)
                        return;
                    "stop" === i && t.stopPropagation()
                }
            }
            ),
            this
        }
        offset(t) {
            if (void 0 !== t)
                return Object.keys(t).forEach(e=>{
                    this.css(e, `${t[e]}px`)
                }
                ),
                this;
            const {offsetTop: e, offsetLeft: i, offsetHeight: s, offsetWidth: l} = this.el;
            return {
                top: e,
                left: i,
                height: s,
                width: l
            }
        }
        scroll(t) {
            const {el: e} = this;
            return void 0 !== t && (void 0 !== t.left && (e.scrollLeft = t.left),
            void 0 !== t.top && (e.scrollTop = t.top)),
            {
                left: e.scrollLeft,
                top: e.scrollTop
            }
        }
        box() {
            return this.el.getBoundingClientRect()
        }
        parent() {
            return new s(this.el.parentNode)
        }
        children(...t) {
            return 0 === arguments.length ? this.el.childNodes : (t.forEach(t=>this.child(t)),
            this)
        }
        child(t) {
            let e = t;
            return "string" == typeof t ? e = document.createTextNode(t) : t instanceof s && (e = t.el),
            this.el.appendChild(e),
            this
        }
        contains(t) {
            return this.el.contains(t)
        }
        className(t) {
            return void 0 !== t ? (this.el.className = t,
            this) : this.el.className
        }
        addClass(t) {
            return this.el.classList.add(t),
            this
        }
        hasClass(t) {
            return this.el.classList.contains(t)
        }
        removeClass(t) {
            return this.el.classList.remove(t),
            this
        }
        toggle(t="active") {
            return this.toggleClass(t)
        }
        toggleClass(t) {
            return this.el.classList.toggle(t)
        }
        active(t=!0) {
            return t ? this.addClass("active") : this.removeClass("active"),
            this
        }
        disabled(t=!0) {
            return t ? this.addClass("disabled") : this.removeClass("disabled"),
            this
        }
        attr(t, e) {
            if (void 0 !== e)
                this.el.setAttribute(t, e);
            else {
                if ("string" == typeof t)
                    return this.el.getAttribute(t);
                Object.keys(t).forEach(e=>{
                    this.el.setAttribute(e, t[e])
                }
                )
            }
            return this
        }
        removeAttr(t) {
            return this.el.removeAttribute(t),
            this
        }
        html(t) {
            return void 0 !== t ? (this.el.innerHTML = t,
            this) : this.el.innerHTML
        }
        val(t) {
            return void 0 !== t ? (this.el.value = t,
            this) : this.el.value
        }
        cssRemoveKeys(...t) {
            return t.forEach(t=>this.el.style.removeProperty(t)),
            this
        }
        css(t, e) {
            return void 0 === e && "string" != typeof t ? (Object.keys(t).forEach(e=>{
                this.el.style[e] = t[e]
            }
            ),
            this) : void 0 !== e ? (this.el.style[t] = e,
            this) : this.el.style[t]
        }
        computedStyle() {
            return window.getComputedStyle(this.el, null)
        }
        show() {
            return this.css("display", "block"),
            this
        }
        hide() {
            return this.css("display", "none"),
            this
        }
    }
    const l = (t,e="")=>new s(t,e)
      , r = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    function h(t) {
        let e = ""
          , i = t;
        for (; i >= r.length; )
            i /= r.length,
            i -= 1,
            e += r[parseInt(i, 10) % r.length];
        const s = t % r.length;
        return e += r[s]
    }
    function n(t) {
        let e = 0;
        for (let i = 0; i < t.length - 1; i += 1) {
            const s = t.charCodeAt(i) - 65
              , l = t.length - 1 - i;
            e += r.length ** l + r.length * s
        }
        return e += t.charCodeAt(t.length - 1) - 65
    }
    function o(t) {
        let e = ""
          , i = "";
        for (let s = 0; s < t.length; s += 1)
            t.charAt(s) >= "0" && t.charAt(s) <= "9" ? i += t.charAt(s) : e += t.charAt(s);
        return [n(e), parseInt(i, 10) - 1]
    }
    function c(t, e, i) {
        const [s,l] = o(t);
        return h(s + e) + (l + i)
    }
    function a(t, e) {
        return `${h(t)}${e + 1}`
    }
    class d {
        constructor(t, e, i, s) {
            this.sri = t,
            this.sci = e,
            this.eri = i,
            this.eci = s
        }
        set(t, e, i, s) {
            this.sri = t,
            this.sci = e,
            this.eri = i,
            this.eci = s
        }
        multiple() {
            return this.eri - this.sri > 0 || this.eci - this.sci > 0
        }
        includes(...t) {
            let[e,i] = [0, 0];
            1 === t.length ? [e,i] = o(t[0]) : 2 === t.length && ([e,i] = t);
            const {sri: s, sci: l, eri: r, eci: h} = this;
            return s <= e && e <= r && l <= i && i <= h
        }
        each(t) {
            const {sri: e, sci: i, eri: s, eci: l} = this;
            for (let r = e; r <= s; r += 1)
                for (let e = i; e <= l; e += 1)
                    t(r, e)
        }
        within(t) {
            return this.sri >= t.sri && this.sci >= t.sci && this.eri <= t.eri && this.eci <= t.eci
        }
        disjoint(t) {
            return this.sri > t.eri || this.sci > t.eci || t.sri > this.eri || t.sci > this.eci
        }
        intersects(t) {
            return this.sri <= t.eri && this.sci <= t.eci && t.sri <= this.eri && t.sci <= this.eci
        }
        union(t) {
            const {sri: e, sci: i, eri: s, eci: l} = this;
            return new d(t.sri < e ? t.sri : e,t.sci < i ? t.sci : i,t.eri > s ? t.eri : s,t.eci > l ? t.eci : l)
        }
        size() {
            return [this.eri - this.sri + 1, this.eci - this.sci + 1]
        }
        toString() {
            const {sri: t, sci: e, eri: i, eci: s} = this;
            return `${a(e, t)}:${a(s, i)}`
        }
        toJSON() {
            return this.toString()
        }
        equals(t) {
            return this.eri === t.eri && this.eci === t.eci && this.sri === t.sri && this.sci === t.sci
        }
        static valueOf(t) {
            const e = t.split(":")
              , [i,s] = o(e[0]);
            let[l,r] = [i, s];
            return e.length > 1 && ([l,r] = o(e[1])),
            new d(i,s,l,r)
        }
    }
    class f {
        constructor() {
            this.range = new d(0,0,0,0),
            this.ri = 0,
            this.ci = 0
        }
        multiple() {
            return this.range.multiple()
        }
        setIndexes(t, e) {
            this.ri = t,
            this.ci = e
        }
        size() {
            return this.range.size()
        }
    }
    class u {
        constructor() {
            this.x = 0,
            this.y = 0,
            this.ri = 0,
            this.ci = 0
        }
    }
    const g = (t={},...e)=>(e.forEach(e=>{
        Object.keys(e).forEach(i=>{
            const s = e[i];
            "string" == typeof s || "number" == typeof s || "boolean" == typeof s ? t[i] = s : "function" != typeof s && !Array.isArray(s) && s instanceof Object ? (t[i] = t[i] || {},
            g(t[i], s)) : t[i] = s
        }
        )
    }
    ),
    t);
    var p = {
        cloneDeep: function(t) {
            return JSON.parse(JSON.stringify(t))
        },
        merge: (...t)=>g({}, ...t),
        equals: function t(e, i) {
            const s = Object.keys(e);
            if (s.length !== Object.keys(i).length)
                return !1;
            for (let l = 0; l < s.length; l += 1) {
                const r = s[l]
                  , h = e[r]
                  , n = i[r];
                if (void 0 === n)
                    return !1;
                if ("string" == typeof h || "number" == typeof h || "boolean" == typeof h) {
                    if (h !== n)
                        return !1
                } else if (Array.isArray(h)) {
                    if (h.length !== n.length)
                        return !1;
                    for (let e = 0; e < h.length; e += 1)
                        if (!t(h[e], n[e]))
                            return !1
                } else if ("function" != typeof h && !Array.isArray(h) && h instanceof Object && !t(h, n))
                    return !1
            }
            return !0
        },
        sum: (t,e=(t=>t))=>{
            let i = 0
              , s = 0;
            return Object.keys(t).forEach(l=>{
                i += e(t[l], l),
                s += 1
            }),
            [i, s]
        }
        ,
        rangeEach: function(t, e, i) {
            for (let s = t; s < e; s += 1)
                i(s)
        },
        rangeSum: function(t, e, i) {
            let s = 0;
            for (let l = t; l < e; l += 1)
                s += i(l);
            return s
        },
        rangeReduceIf: function(t, e, i, s, l, r) {
            let h = i
              , n = s
              , o = t;
            for (; o < e && !(h > l); o += 1)
                h += n = r(o);
            return [o, h - n, n]
        },
        deleteProperty: function(t, e) {
            const i = t[`${e}`];
            return delete t[`${e}`],
            i
        }
    };
    class m {
        constructor() {
            this.undoItems = [],
            this.redoItems = []
        }
        add(t) {
            this.undoItems.push(p.cloneDeep(t)),
            this.redoItems = []
        }
        canUndo() {
            return this.undoItems.length > 0
        }
        canRedo() {
            return this.redoItems.length > 0
        }
        undo(t, e) {
            const {undoItems: i, redoItems: s} = this;
            this.canUndo() && (s.push(p.cloneDeep(t)),
            e(i.pop()))
        }
        redo(t, e) {
            const {undoItems: i, redoItems: s} = this;
            this.canRedo() && (i.push(p.cloneDeep(t)),
            e(s.pop()))
        }
    }
    class w {
        constructor() {
            this.range = null,
            this.state = "clear"
        }
        copy(t) {
            return this.range = t,
            this.state = "copy",
            this
        }
        cut(t) {
            return this.range = t,
            this.state = "cut",
            this
        }
        isCopy() {
            return "copy" === this.state
        }
        isCut() {
            return "cut" === this.state
        }
        isClear() {
            return "clear" === this.state
        }
        clear() {
            this.range = null,
            this.state = "clear"
        }
    }
    class b {
        constructor(t=[]) {
            this._ = t
        }
        forEach(t) {
            this._.forEach(t)
        }
        deleteWithin(t) {
            this._ = this._.filter(e=>!e.within(t))
        }
        getFirstIncludes(t, e) {
            for (let i = 0; i < this._.length; i += 1) {
                const s = this._[i];
                if (s.includes(t, e))
                    return s
            }
            return null
        }
        filterIntersects(t) {
            return new b(this._.filter(e=>e.intersects(t)))
        }
        union(t) {
            let e = t;
            return this._.forEach(i=>{
                i.intersects(t) && (e = i.union(e))
            }
            ),
            e
        }
        add(t) {
            this.deleteWithin(t),
            this._.push(t)
        }
        shift(t, e, i, s) {
            this._.forEach(l=>{
                const {sri: r, sci: h, eri: n, eci: o} = l
                  , c = l;
                "row" === t ? r > e ? (c.sri += i,
                c.eri += i) : r < e && e <= n && (c.eri += i,
                s(r, h, i, 0)) : "column" === t && (h > e ? (c.sci += i,
                c.eci += i) : h < e && e <= o && (c.eci += i,
                s(r, h, 0, i)))
            }
            )
        }
        move(t, e, i) {
            this._.forEach(s=>{
                const l = s;
                l.within(t) && (l.sri += e,
                l.sci += i)
            }
            )
        }
        setData(t) {
            return this._ = t.map(t=>d.valueOf(t)),
            this
        }
        getData() {
            return this._.map(t=>t.toString())
        }
    }
    class y {
        constructor({len: t, height: e}) {
            this._ = {},
            this.len = t,
            this.height = e
        }
        getHeight(t) {
            const e = this.get(t);
            return e && e.height ? e.height : this.height
        }
        setHeight(t, e) {
            this.getOrNew(t).height = e
        }
        setStyle(t, e) {
            this.getOrNew(t).style = e
        }
        sumHeight(t, e) {
            return p.rangeSum(t, e, t=>this.getHeight(t))
        }
        totalHeight() {
            return this.sumHeight(0, this.len)
        }
        get(t) {
            return this._[t]
        }
        getOrNew(t) {
            return this._[t] = this._[t] || {
                cells: {}
            },
            this._[t]
        }
        getCell(t, e) {
            const i = this.get(t);
            return void 0 !== i && void 0 !== i.cells && void 0 !== i.cells[e] ? i.cells[e] : null
        }
        getCellMerge(t, e) {
            const i = this.getCell(t, e);
            return i && i.merge ? i.merge : [0, 0]
        }
        getCellOrNew(t, e) {
            const i = this.getOrNew(t);
            return i.cells[e] = i.cells[e] || {},
            i.cells[e]
        }
        setCell(t, e, i, s="all") {
            const l = this.getOrNew(t);
            "all" === s ? l.cells[e] = i : "text" === s ? (l.cells[e] = l.cells[e] || {},
            l.cells[e].text = i.text) : "format" === s && (l.cells[e] = l.cells[e] || {},
            l.cells[e].style = i.style,
            i.merge && (l.cells[e].merge = i.merge))
        }
        setCellText(t, e, i) {
            this.getCellOrNew(t, e).text = i
        }
        copyPaste(t, e, i, s=!1, l=(()=>{}
        )) {
            const {sri: r, sci: h, eri: n, eci: o} = t
              , a = e.sri
              , d = e.sci
              , f = e.eri
              , u = e.eci
              , [g,m] = t.size()
              , [w,b] = e.size();
            let y = !0
              , v = 0;
            (f < r || u < h) && (y = !1,
            v = f < r ? w : b);
            for (let t = r; t <= n; t += 1)
                if (this._[t])
                    for (let e = h; e <= o; e += 1)
                        if (this._[t].cells && this._[t].cells[e])
                            for (let n = a; n <= f; n += g)
                                for (let o = d; o <= u; o += m) {
                                    const f = n + (t - r)
                                      , u = o + (e - h)
                                      , g = p.cloneDeep(this._[t].cells[e]);
                                    if (s && g && g.text && g.text.length > 0) {
                                        const {text: t} = g;
                                        let e = o - d + (n - a) + 1;
                                        if (y || (e -= v + 1),
                                        "=" === t[0])
                                            g.text = t.replace(/\w{1,3}\d/g, t=>{
                                                let[i,s] = [0, 0];
                                                return r === a ? i = e : s = e,
                                                c(t, i, s)
                                            }
                                            );
                                        else {
                                            const i = /[\\.\d]+$/.exec(t);
                                            if (null !== i) {
                                                const s = Number(i[0]) + e;
                                                g.text = t.substring(0, i.index) + s
                                            }
                                        }
                                    }
                                    this.setCell(f, u, g, i),
                                    l(f, u, g)
                                }
        }
        cutPaste(t, e) {
            const i = {};
            this.each(s=>{
                this.eachCells(s, l=>{
                    let r = parseInt(s, 10)
                      , h = parseInt(l, 10);
                    t.includes(s, l) && (r = e.sri + (r - t.sri),
                    h = e.sci + (h - t.sci)),
                    i[r] = i[r] || {
                        cells: {}
                    },
                    i[r].cells[h] = this._[s].cells[l]
                }
                )
            }
            ),
            this._ = i
        }
        insert(t, e=1) {
            const i = {};
            this.each((s,l)=>{
                let r = parseInt(s, 10);
                r >= t && (r += e),
                i[r] = l
            }
            ),
            this._ = i,
            this.len += e
        }
        delete(t, e) {
            const i = e - t + 1
              , s = {};
            this.each((l,r)=>{
                const h = parseInt(l, 10);
                h < t ? s[h] = r : l > e && (s[h - i] = r)
            }
            ),
            this._ = s,
            this.len -= i
        }
        insertColumn(t, e=1) {
            this.each((i,s)=>{
                const l = {};
                this.eachCells(i, (i,s)=>{
                    let r = parseInt(i, 10);
                    r >= t && (r += e),
                    l[r] = s
                }
                ),
                s.cells = l
            }
            )
        }
        deleteColumn(t, e) {
            const i = e - t + 1;
            this.each((s,l)=>{
                const r = {};
                this.eachCells(s, (s,l)=>{
                    const h = parseInt(s, 10);
                    h < t ? r[h] = l : h > e && (r[h - i] = l)
                }
                ),
                l.cells = r
            }
            )
        }
        deleteCells(t, e="all") {
            t.each((t,i)=>{
                this.deleteCell(t, i, e)
            }
            )
        }
        deleteCell(t, e, i="all") {
            const s = this.get(t);
            if (null !== s) {
                const l = this.getCell(t, e);
                null !== l && ("all" === i ? delete s.cells[e] : "text" === i ? (l.text && delete l.text,
                l.value && delete l.value) : "format" === i ? (void 0 !== l.style && delete l.style,
                l.merge && delete l.merge) : "merge" === i && l.merge && delete l.merge)
            }
        }
        each(t) {
            Object.entries(this._).forEach(([e,i])=>{
                t(e, i)
            }
            )
        }
        eachCells(t, e) {
            this._[t] && this._[t].cells && Object.entries(this._[t].cells).forEach(([t,i])=>{
                e(t, i)
            }
            )
        }
        setData(t) {
            this._ = t
        }
        getData() {
            return this._
        }
    }
    class v {
        constructor({len: t, width: e, indexWidth: i, minWidth: s}) {
            this._ = {},
            this.len = t,
            this.width = e,
            this.indexWidth = i,
            this.minWidth = s
        }
        setData(t) {
            this._ = t
        }
        getData() {
            return this._
        }
        getWidth(t) {
            const e = this._[t];
            return e && e.width ? e.width : this.width
        }
        getOrNew(t) {
            return this._[t] = this._[t] || {},
            this._[t]
        }
        setWidth(t, e) {
            this.getOrNew(t).width = e
        }
        setStyle(t, e) {
            this.getOrNew(t).style = e
        }
        sumWidth(t, e) {
            return p.rangeSum(t, e, t=>this.getWidth(t))
        }
        totalWidth() {
            return this.sumWidth(0, this.len)
        }
    }
    const x = {
        view: {
            height: ()=>document.documentElement.clientHeight,
            width: ()=>document.documentElement.clientWidth
        },
        showGrid: !0,
        showToolbar: !0,
        row: {
            len: 100,
            height: 25
        },
        col: {
            len: 26,
            width: 100,
            indexWidth: 60,
            minWidth: 60
        },
        style: {
            bgcolor: "#ffffff",
            align: "left",
            valign: "middle",
            textwrap: !1,
            strike: !1,
            underline: !1,
            color: "#0a0a0a",
            font: {
                name: "Helvetica",
                size: 10,
                bold: !1,
                italic: !1
            }
        }
    }, 
    C = 41;
    function k(t, e, i, s=!1) {
        const {rows: l, merges: r} = this;
        "all" !== i && "format" !== i || (l.deleteCells(e, i),
        r.deleteWithin(e)),
        l.copyPaste(t, e, i, s, (t,e,i)=>{
            if (i && i.merge) {
                const [s,l] = i.merge;
                if (s <= 0 && l <= 0)
                    return;
                r.add(new d(t,e,t + s,e + l))
            }
        })
    }
    function E(t, e, i) {
        const {styles: s, rows: l} = this
          , r = l.getCellOrNew(t, e);
        let h = {};
        void 0 !== r.style && (h = p.cloneDeep(s[r.style])),
        Object.assign(h, {
            border: i
        }),
        r.style = this.addStyle(h)
    }
    class S {
        constructor(t, e) {
            this.settings = p.merge(x, e || {}),
            this.name = t || "sheet",
            this.freeze = [0, 0],
            this.styles = [],
            this.merges = new b,
            this.rows = new y(this.settings.row),
            this.cols = new v(this.settings.col),
            this.hyperlinks = {},
            this.comments = {},
            this.selector = new f,
            this.scroll = new u,
            this.history = new m,
            this.clipboard = new w,
            this.change = (()=>{}
            )
        }
        canUndo() {
            return this.history.canUndo()
        }
        canRedo() {
            return this.history.canRedo()
        }
        undo() {
            this.history.undo(this.getData(), t=>{
                this.setData(t)
            }
            )
        }
        redo() {
            this.history.redo(this.getData(), t=>{
                this.setData(t)
            }
            )
        }
        copy() {
            this.clipboard.copy(this.selector.range)
        }
        cut() {
            this.clipboard.cut(this.selector.range)
        }
        paste(t="all") {
            const {clipboard: e, selector: i} = this;
            e.isClear() || this.changeData(()=>{
                e.isCopy() ? k.call(this, e.range, i.range, t) : e.isCut() && function(t, e) {
                    const {clipboard: i, rows: s, merges: l} = this;
                    s.cutPaste(t, e),
                    l.move(t, e.sri - t.sri, e.sci - t.sci),
                    i.clear()
                }
                .call(this, e.range, i.range)
            }
            )
        }
        autofill(t, e) {
            this.changeData(()=>{
                k.call(this, this.selector.range, t, e, !0)
            }
            )
        }
        clearClipboard() {
            this.clipboard.clear()
        }
        calSelectedRangeByEnd(t, e) {
            const {selector: i, rows: s, cols: l, merges: r} = this;
            let {sri: h, sci: n, eri: o, eci: c} = i.range;
            const a = i.ri
              , f = i.ci;
            let[u,g] = [t, e];
            return t < 0 && (u = s.len - 1),
            e < 0 && (g = l.len - 1),
            u <= a ? [h,o] = [u, a] : o = u,
            g <= f ? [n,c] = [g, f] : c = g,
            i.range = r.union(new d(h,n,o,c)),
            i.range
        }
        calSelectedRangeByStart(t, e) {
            const {selector: i, rows: s, cols: l, merges: r} = this;
            let h = r.getFirstIncludes(t, e);
            return null === h && (h = new d(t,e,t,e),
            -1 === t && (h.sri = 0,
            h.eri = s.len - 1),
            -1 === e && (h.sci = 0,
            h.eci = l.len - 1)),
            i.range = h,
            h
        }
        setSelectedCellAttr(t, e) {
            this.changeData(()=>{
                const {selector: i, styles: s, rows: l} = this;
                if ("merge" === t)
                    e ? this.merge() : this.unmerge();
                else if ("border" === t)
                    (function({mode: t, style: e, color: i}) {
                        const {styles: s, selector: l, rows: r} = this
                          , {sri: h, sci: n, eri: o, eci: c} = l.range
                          , a = !this.isSignleSelected();
                        if (a || "inside" !== t && "horizontal" !== t && "vertical" !== t)
                            if ("outside" !== t || a) {
                                if ("none" === t)
                                    l.range.each((t,e)=>{
                                        const i = r.getCell(t, e);
                                        if (i && void 0 !== i.style) {
                                            const t = p.cloneDeep(s[i.style]);
                                            delete t.border,
                                            i.style = this.addStyle(t)
                                        }
                                    }
                                    );
                                else if ("all" === t || "inside" === t || "outside" === t || "horizontal" === t || "vertical" === t) {
                                    const s = [];
                                    for (let l = h; l <= o; l += 1)
                                        for (let d = n; d <= c; d += 1) {
                                            const f = [];
                                            for (let t = 0; t < s.length; t += 1) {
                                                const [e,i,r,h] = s[t];
                                                if (l === e + r + 1 && f.push(t),
                                                e <= l && l <= e + r && d === i) {
                                                    d += h + 1;
                                                    break
                                                }
                                            }
                                            if (f.forEach(t=>s.splice(t, 1)),
                                            d > c)
                                                break;
                                            const u = r.getCell(l, d);
                                            let[g,p] = [0, 0];
                                            u && u.merge && ([g,p] = u.merge,
                                            s.push([l, d, g, p]));
                                            const m = g > 0 && l + g === o
                                              , w = p > 0 && d + p === c;
                                            let b = {};
                                            "all" === t ? b = {
                                                bottom: [e, i],
                                                top: [e, i],
                                                left: [e, i],
                                                right: [e, i]
                                            } : "inside" === t ? (!w && d < c && (b.right = [e, i]),
                                            !m && l < o && (b.bottom = [e, i])) : "horizontal" === t ? !m && l < o && (b.bottom = [e, i]) : "vertical" === t ? !w && d < c && (b.right = [e, i]) : "outside" === t && a && (h === l && (b.top = [e, i]),
                                            (m || o === l) && (b.bottom = [e, i]),
                                            n === d && (b.left = [e, i]),
                                            (w || c === d) && (b.right = [e, i])),
                                            Object.keys(b).length > 0 && E.call(this, l, d, b),
                                            d += p
                                        }
                                } else if ("top" === t || "bottom" === t)
                                    for (let s = n; s <= c; s += 1)
                                        "top" === t && (E.call(this, h, s, {
                                            top: [e, i]
                                        }),
                                        s += r.getCellMerge(h, s)[1]),
                                        "bottom" === t && (E.call(this, o, s, {
                                            bottom: [e, i]
                                        }),
                                        s += r.getCellMerge(o, s)[1]);
                                else if ("left" === t || "right" === t)
                                    for (let s = h; s <= o; s += 1)
                                        "left" === t && (E.call(this, s, n, {
                                            left: [e, i]
                                        }),
                                        s += r.getCellMerge(s, n)[0]),
                                        "right" === t && (E.call(this, s, c, {
                                            right: [e, i]
                                        }),
                                        s += r.getCellMerge(s, c)[0])
                            } else
                                E.call(this, h, n, {
                                    top: [e, i],
                                    bottom: [e, i],
                                    left: [e, i],
                                    right: [e, i]
                                })
                    }
                    ).call(this, e);
                else if ("formula" === t) {
                    l.getCellOrNew(i.ri, i.ci).text = `=${e}()`
                } else
                    i.range.each((i,r)=>{
                        const h = l.getCellOrNew(i, r);
                        let n = {};
                        if (void 0 !== h.style && (n = p.cloneDeep(s[h.style])),
                        "format" === t)
                            n.format = e,
                            h.style = this.addStyle(n);
                        else if ("font-bold" === t || "font-italic" === t || "font-name" === t || "font-size" === t) {
                            const i = {};
                            i[t.split("-")[1]] = e,
                            n.font = Object.assign(n.font || {}, i),
                            h.style = this.addStyle(n)
                        } else
                            "strike" !== t && "textwrap" !== t && "underline" !== t && "align" !== t && "valign" !== t && "color" !== t && "bgcolor" !== t || (n[t] = e,
                            h.style = this.addStyle(n))
                    }
                    )
            }
            )
        }
        setSelectedCellText(t, e="input") {
            const {ri: i, ci: s} = this.selector;
            this.setCellText(i, s, t, e)
        }
        getSelectedCell() {
            const {ri: t, ci: e} = this.selector;
            return this.rows.getCell(t, e)
        }
        xyInSelectedRect(t, e) {
            const {left: i, top: s, width: l, height: r} = this.getSelectedRect()
              , h = t - this.cols.indexWidth
              , n = e - this.rows.height;
            return h > i && h < i + l && n > s && n < s + r
        }
        getSelectedRect() {
            return this.getRect(this.selector.range)
        }
        getClipboardRect() {
            const {clipboard: t} = this;
            return t.isClear() ? {
                left: -100,
                top: -100
            } : this.getRect(t.range)
        }
        getRect(t) {
            const {scroll: e, rows: i, cols: s} = this
              , {sri: l, sci: r, eri: h, eci: n} = t;
            if (l < 0 && r < 0)
                return {
                    left: 0,
                    l: 0,
                    top: 0,
                    t: 0,
                    scroll: e
                };
            const {left: o, top: c} = this.cellPosition(l, r)
              , a = i.sumHeight(l, h + 1)
              , d = s.sumWidth(r, n + 1);
            let f = o - e.x
              , u = c - e.y;
            const g = this.freezeTotalHeight()
              , p = this.freezeTotalWidth();
            return p > 0 && p > o && (f = o),
            g > 0 && g > c && (u = c),
            {
                l: o,
                t: c,
                left: f,
                top: u,
                height: a,
                width: d,
                scroll: e
            }
        }
        getCellRectByXY(t, e) {
            const {scroll: i, merges: s, rows: l, cols: r} = this;
            let {ri: h, top: n, height: o} = function(t, e) {
                const {rows: i} = this
                  , s = this.freezeTotalHeight();
                let l = i.height;
                s + i.height < t && (l -= e);
                const [r,h,n] = p.rangeReduceIf(0, i.len, l, i.height, t, t=>i.getHeight(t));
                return h <= 0 ? {
                    ri: -1,
                    top: 0,
                    height: n
                } : {
                    ri: r - 1,
                    top: h,
                    height: n
                }
            }
            .call(this, e, i.y)
              , {ci: c, left: a, width: d} = function(t, e) {
                const {cols: i} = this
                  , s = this.freezeTotalWidth();
                let l = i.indexWidth;
                s + i.indexWidth < t && (l -= e);
                const [r,h,n] = p.rangeReduceIf(0, i.len, l, i.indexWidth, t, t=>i.getWidth(t));
                return h <= 0 ? {
                    ci: -1,
                    left: 0,
                    width: i.indexWidth
                } : {
                    ci: r - 1,
                    left: h,
                    width: n
                }
            }
            .call(this, t, i.x);
            if (-1 === c && (d = r.totalWidth()),
            -1 === h && (o = l.totalHeight()),
            h >= 0 || c >= 0) {
                const t = s.getFirstIncludes(h, c);
                t && (h = t.sri,
                c = t.sci,
                ({left: a, top: n, width: d, height: o} = this.cellRect(h, c)))
            }
            return {
                ri: h,
                ci: c,
                left: a,
                top: n,
                width: d,
                height: o
            }
        }
        isSignleSelected() {
            const {sri: t, sci: e, eri: i, eci: s} = this.selector.range
              , l = this.getCell(t, e);
            if (l && l.merge) {
                const [r,h] = l.merge;
                if (t + r === i && e + h === s)
                    return !0
            }
            return !this.selector.multiple()
        }
        canUnmerge() {
            const {sri: t, sci: e, eri: i, eci: s} = this.selector.range
              , l = this.getCell(t, e);
            if (l && l.merge) {
                const [r,h] = l.merge;
                if (t + r === i && e + h === s)
                    return !0
            }
            return !1
        }
        merge() {
            const {selector: t, rows: e} = this;
            if (this.isSignleSelected())
                return;
            const [i,s] = t.size();
            if (i > 1 || s > 1) {
                const {sri: l, sci: r} = t.range;
                this.changeData(()=>{
                    const h = e.getCellOrNew(l, r);
                    h.merge = [i - 1, s - 1],
                    this.merges.add(t.range),
                    this.rows.deleteCells(t.range),
                    this.rows.setCell(l, r, h)
                }
                )
            }
        }
        unmerge() {
            const {selector: t} = this;
            if (!this.isSignleSelected())
                return;
            const {sri: e, sci: i} = t.range;
            this.changeData(()=>{
                this.rows.deleteCell(e, i, "merge"),
                this.merges.deleteWithin(t.range)
            }
            )
        }
        deleteCell(t="all") {
            const {selector: e} = this;
            this.changeData(()=>{
                this.rows.deleteCells(e.range, t),
                "all" !== t && "format" !== t || this.merges.deleteWithin(e.range)
            }
            )
        }
        insert(t, e=1) {
            this.changeData(()=>{
                const {sri: i, sci: s} = this.selector.range
                  , {rows: l, merges: r, cols: h} = this;
                let n = i;
                "row" === t ? l.insert(i, e) : "column" === t && (l.insertColumn(s, e),
                n = s,
                h.len += 1),
                r.shift(t, n, e, (t,e,i,s)=>{
                    const r = l.getCell(t, e);
                    r.merge[0] += i,
                    r.merge[1] += s
                }
                )
            }
            )
        }
        delete(t) {
            this.changeData(()=>{
                const {rows: e, merges: i, selector: s, cols: l} = this
                  , {range: r} = s
                  , {sri: h, sci: n, eri: o, eci: c} = s.range
                  , [a,d] = s.range.size();
                let f = h
                  , u = a;
                "row" === t ? e.delete(h, o) : "column" === t && (e.deleteColumn(n, c),
                f = r.sci,
                u = d,
                l.len -= 1),
                i.shift(t, f, -u, (t,i,s,l)=>{
                    const r = e.getCell(t, i);
                    r.merge[0] += s,
                    r.merge[1] += l,
                    0 === r.merge[0] && 0 === r.merge[1] && delete r.merge
                }
                )
            }
            )
        }
        scrollx(t, e) {
            const {scroll: i, freeze: s, cols: l} = this
              , [,r] = s
              , [h,n,o] = p.rangeReduceIf(r, l.len, 0, 0, t, t=>l.getWidth(t));
            let c = n;
            t > 0 && (c += o),
            i.x !== c && (i.ci = t > 0 ? h - r : 0,
            i.x = c,
            e())
        }
        scrolly(t, e) {
            const {scroll: i, freeze: s, rows: l} = this
              , [r] = s
              , [h,n,o] = p.rangeReduceIf(r, l.len, 0, 0, t, t=>l.getHeight(t));
            let c = n;
            t > 0 && (c += o),
            i.y !== c && (i.ri = t > 0 ? h - r : 0,
            i.y = c,
            e())
        }
        cellRect(t, e) {
            const {rows: i, cols: s} = this
              , {left: l, top: r} = this.cellPosition(t, e)
              , h = i.getCell(t, e);
            let n = s.getWidth(e)
              , o = i.getHeight(t);
            if (null !== h && h.merge) {
                const [l,r] = h.merge;
                if (l > 0)
                    for (let e = 1; e <= l; e += 1)
                        o += i.getHeight(t + e);
                if (r > 0)
                    for (let t = 1; t <= r; t += 1)
                        n += s.getWidth(e + t)
            }
            return {
                left: l,
                top: r,
                width: n,
                height: o,
                cell: h
            }
        }
        cellPosition(t, e) {
            const {cols: i, rows: s} = this;
            return {
                left: i.sumWidth(0, e),
                top: s.sumHeight(0, t)
            }
        }
        getCell(t, e) {
            return this.rows.getCell(t, e)
        }
        getCellTextOrDefault(t, e) {
            const i = this.getCell(t, e);
            return i && i.text ? i.text : ""
        }
        getCellStyle(t, e) {
            const i = this.getCell(t, e);
            return i && void 0 !== i.style ? this.styles[i.style] : null
        }
        getCellStyleOrDefault(t, e) {
            const {styles: i, rows: s} = this
              , l = s.getCell(t, e)
              , r = l && void 0 !== l.style ? i[l.style] : {};
            return p.merge(this.defaultStyle(), r)
        }
        getSelectedCellStyle() {
            const {ri: t, ci: e} = this.selector;
            return this.getCellStyleOrDefault(t, e)
        }
        setCellText(t, e, i, s) {
            "finished" === s ? (this.rows.setCellText(t, e, ""),
            this.history.add(this.getData()),
            this.rows.setCellText(t, e, i)) : (this.rows.setCellText(t, e, i),
            this.change(this.getData()))
        }
        freezeIsActive() {
            const [t,e] = this.freeze;
            return t > 0 || e > 0
        }
        setFreeze(t, e) {
            this.changeData(()=>{
                this.freeze = [t, e]
            }
            )
        }
        freezeTotalWidth() {
            return this.cols.sumWidth(0, this.freeze[1])
        }
        freezeTotalHeight() {
            return this.rows.sumHeight(0, this.freeze[0])
        }
        setRowHeight(t, e) {
            this.changeData(()=>{
                this.rows.setHeight(t, e)
            }
            )
        }
        setColWidth(t, e) {
            this.changeData(()=>{
                this.cols.setWidth(t, e)
            }
            )
        }
        viewHeight() {
            const {view: t, showToolbar: e} = this.settings;
            let i = t.height();
            return e && (i -= C),
            i
        }
        viewWidth() {
            return this.settings.view.width()
        }
        freezeViewRange() {
            const [t,e] = this.freeze;
            return new d(0,0,t,e)
        }
        viewRange() {
            const {scroll: t, rows: e, cols: i} = this
              , {ri: s, ci: l} = t;
            let[r,h] = [0, 0]
              , [n,o] = [e.len, i.len];
            for (let t = s; t < e.len && (n = t,
            !((h += e.getHeight(t)) > this.viewHeight())); t += 1)
                ;
            for (let t = l; t < i.len && (o = t,
            !((r += i.getWidth(t)) > this.viewWidth())); t += 1)
                ;
            return new d(s,l,n,o)
        }
        eachMergesInView(t, e) {
            this.merges.filterIntersects(t).forEach(t=>e(t))
        }
        rowEach(t, e, i) {
            let s = 0;
            const {rows: l} = this;
            for (let r = t; r <= e; r += 1) {
                const t = l.getHeight(r);
                if (i(r, s, t),
                (s += t) > this.viewHeight())
                    break
            }
        }
        colEach(t, e, i) {
            let s = 0;
            const {cols: l} = this;
            for (let r = t; r <= e; r += 1) {
                const t = l.getWidth(r);
                if (i(r, s, t),
                (s += t) > this.viewWidth())
                    break
            }
        }
        defaultStyle() {
            return this.settings.style
        }
        addStyle(t) {
            const {styles: e} = this;
            for (let i = 0; i < e.length; i += 1) {
                const s = e[i];
                if (p.equals(s, t))
                    return i
            }
            return e.push(t),
            e.length - 1
        }
        changeData(t) {
            this.history.add(this.getData()),
            t(),
            this.change(this.getData())
        }
        setData(t) {
            return Object.keys(t).forEach(e=>{
                "merges" === e || "rows" === e || "cols" === e ? this[e].setData(t[e]) : "freeze" === e ? this.freeze = o(t[e]) : void 0 !== t[e] && (this[e] = t[e])
            }
            ),
            this
        }
        getData() {
            const {name: t, freeze: e, styles: i, merges: s, rows: l, cols: r} = this;
            return {
                name: t,
                freeze: a(...e),
                styles: i,
                merges: s.getData(),
                rows: l.getData(),
                cols: r.getData()
            }
        }
    }
    function z(t, e, i) {
        t.addEventListener(e, i)
    }
    function T(t, e, i) {
        t.removeEventListener(e, i)
    }
    function $(t, e, i) {
        z(t, "mousemove", e),
        t.xEvtUp = (s=>{
            T(t, "mousemove", e),
            T(t, "mouseup", t.xEvtUp),
            i(s)
        }
        ),
        z(t, "mouseup", t.xEvtUp)
    }
    function O(t, e, i, s) {
        let l = "";
        s(l = Math.abs(t) > Math.abs(e) ? t > 0 ? "right" : "left" : e > 0 ? "down" : "up", e, i)
    }
    const D = "x-spreadsheet";
    window.devicePixelRatio;
    class W {
        constructor(t=!1, e) {
            this.moving = !1,
            this.vertical = t,
            this.el = l("div", `${D}-resizer ${t ? "vertical" : "horizontal"}`)
            	.children(this.hoverEl = l("div", `${D}-resizer-hover`)
            	.on("mousedown.stop", t=>this.mousedownHandler(t)), 
            this.lineEl = l("div", `${D}-resizer-line`).hide()).hide(),
            this.cRect = null,
            this.finishedFn = null,
            this.minDistance = e
        }
        show(t, e) {
            const {moving: i, vertical: s, hoverEl: l, lineEl: r, el: h} = this;
            if (i) return;
            this.cRect = t;
            const {left: n, top: o, width: c, height: a} = t;
            h.offset({
                left: s ? n + c - 5 : n,
                top: s ? o : o + a - 5
            }).show(),
            l.offset({
                width: s ? 5 : c,
                height: s ? a : 5
            }),
            r.offset({
                width: s ? 0 : e.width,
                height: s ? e.height : 0
            })
        }
        hide() {
            this.el.offset({
                left: 0,
                top: 0
            }).hide()
        }
        mousedownHandler(t) {
            let e = t;
            const {el: i, lineEl: s, cRect: l, vertical: r, minDistance: h} = this;
            let n = r ? l.width : l.height;
            s.show(),
            $(window, t=>{
                this.moving = !0,
                null !== e && 1 === t.buttons && (r ? (n += t.movementX) > h && i.css("left", `${l.left + n}px`) : (n += t.movementY) > h && i.css("top", `${l.top + n}px`),
                e = t)
            }, 
            ()=>{
                e = null,
                s.hide(),
                this.moving = !1,
                this.hide(),
                this.finishedFn && (n < h && (n = h),
                this.finishedFn(l, n))
            })
        }
    }
    class R {
        constructor(t) {
            this.vertical = t,
            this.moveFn = null,
            this.el = l("div", `${D}-scrollbar ${t ? "vertical" : "horizontal"}`)
            	.child(this.contentEl = l("div", ""))
            	.on("mousemove.stop", ()=>{})
            	.on("scroll.stop", t=>{
	                const {scrollTop: e, scrollLeft: i} = t.target;
	                this.moveFn && this.moveFn(this.vertical ? e : i, t)
	            }
            )
        }
        move(t) {
            return this.el.scroll(t),
            this
        }
        scroll() {
            return this.el.scroll()
        }
        set(t, e) {
            const i = t - 1;
            if (e > i) {
                const t = this.vertical ? "height" : "width";
                this.el.css(t, `${i}px`).show(),
                this.contentEl.css(this.vertical ? "width" : "height", "1px").css(t, `${e}px`)
            } else
                this.el.hide();
            return this
        }
    }
    const A = 3;
    let I = 10;
    class N {
        constructor() {
            this.cornerEl = l("div", `${D}-selector-corner`),
            this.areaEl = l("div", `${D}-selector-area`).child(this.cornerEl).hide(),
            this.clipboardEl = l("div", `${D}-selector-clipboard`).hide(),
            this.autofillEl = l("div", `${D}-selector-autofill`).hide(),
            this.el = l("div", `${D}-selector`).css("z-index", `${I}`).children(this.areaEl, this.clipboardEl, this.autofillEl).hide(),
            I += 1
        }
        setOffset(t) {
            return this.el.offset(t).show(),
            this
        }
        hide() {
            return this.el.hide(),
            this
        }
        setAreaOffset(t) {
            const {left: e, top: i, width: s, height: l} = t;
            this.areaEl.offset({
                width: s - A + .8,
                height: l - A + .8,
                left: e - .8,
                top: i - .8
            }).show()
        }
        setClipboardOffset(t) {
            const {left: e, top: i, width: s, height: l} = t;
            this.clipboardEl.offset({
                left: e,
                top: i,
                width: s - 5,
                height: l - 5
            })
        }
        showAutofill(t) {
            const {left: e, top: i, width: s, height: l} = t;
            this.autofillEl.offset({
                width: s - A,
                height: l - A,
                left: e,
                top: i
            }).show()
        }
        hideAutofill() {
            this.autofillEl.hide()
        }
        showClipboard() {
            this.clipboardEl.show()
        }
        hideClipboard() {
            this.clipboardEl.hide()
        }
    }
    function H(t) {
        const {data: e} = this
          , {left: i, top: s, width: l, height: r, scroll: h, l: n, t: o} = t
          , c = e.freezeTotalWidth()
          , a = e.freezeTotalHeight();
        let d = i - c;
        c > n && (d -= h.x);
        let f = s - a;
        return a > o && (f -= h.y),
        {
            left: d,
            top: f,
            width: l,
            height: r
        }
    }
    function F(t) {
        const {data: e} = this
          , {left: i, width: s, height: l, l: r, t: h, scroll: n} = t
          , o = e.freezeTotalWidth();
        let c = i - o;
        return o > r && (c -= n.x),
        {
            left: c,
            top: h,
            width: s,
            height: l
        }
    }
    function _(t) {
        const {data: e} = this
          , {top: i, width: s, height: l, l: r, t: h, scroll: n} = t
          , o = e.freezeTotalHeight();
        let c = i - o;
        return o > h && (c -= n.y),
        {
            left: r,
            top: c,
            width: s,
            height: l
        }
    }
    function P(t) {
        const {br: e} = this;
        e.setAreaOffset(H.call(this, t))
    }
    function M(t) {
        const {t: e} = this;
        e.setAreaOffset(F.call(this, t))
    }
    function B(t) {
        const {l: e} = this;
        e.setAreaOffset(_.call(this, t))
    }
    function j(t) {
        const {l: e} = this;
        e.setClipboardOffset(_.call(this, t))
    }
    function L(t) {
        const {br: e} = this;
        e.setClipboardOffset(H.call(this, t))
    }
    function U(t) {
        const {t: e} = this;
        e.setClipboardOffset(F.call(this, t))
    }
    function X(t) {
        P.call(this, t),
        function(t) {
            const {tl: e} = this;
            e.setAreaOffset(t)
        }
        .call(this, t),
        M.call(this, t),
        B.call(this, t)
    }
    function Y(t) {
        L.call(this, t),
        function(t) {
            const {tl: e} = this;
            e.setClipboardOffset(t)
        }
        .call(this, t),
        U.call(this, t),
        j.call(this, t)
    }
    class V {
        constructor(t) {
            this.data = t,
            this.br = new N,
            this.t = new N,
            this.l = new N,
            this.tl = new N,
            this.br.el.show(),
            this.offset = null,
            this.areaOffset = null,
            this.indexes = null,
            this.range = null,
            this.arange = null,
            this.el = l("div", `${D}-selectors`).children(this.tl.el, this.t.el, this.l.el, this.br.el).hide(),
            I += 1
        }
        hide() {
            this.el.hide()
        }
        resetOffset() {
            const {data: t, tl: e, t: i, l: s, br: l} = this
              , r = t.freezeTotalHeight()
              , h = t.freezeTotalWidth();
            r > 0 || h > 0 ? (e.setOffset({
                width: h,
                height: r
            }),
            i.setOffset({
                left: h,
                height: r
            }),
            s.setOffset({
                top: r,
                width: h
            }),
            l.setOffset({
                left: h,
                top: r
            })) : (e.hide(),
            i.hide(),
            s.hide(),
            l.setOffset({
                left: 0,
                top: 0
            }))
        }
        resetAreaOffset() {
            const t = this.data.getSelectedRect()
              , e = this.data.getClipboardRect();
            X.call(this, t),
            Y.call(this, e),
            this.resetOffset()
        }
        resetBRTAreaOffset() {
            const t = this.data.getSelectedRect()
              , e = this.data.getClipboardRect();
            P.call(this, t),
            M.call(this, t),
            L.call(this, e),
            U.call(this, e),
            this.resetOffset()
        }
        resetBRLAreaOffset() {
            const t = this.data.getSelectedRect()
              , e = this.data.getClipboardRect();
            P.call(this, t),
            B.call(this, t),
            L.call(this, e),
            j.call(this, e),
            this.resetOffset()
        }
        set(t, e, i=!0) {
            const {data: s} = this
              , l = s.calSelectedRangeByStart(t, e)
              , {sri: r, sci: h} = l;
            if (i) {
                let[i,l] = [t, e];
                t < 0 && (i = 0),
                e < 0 && (l = 0),
                s.selector.setIndexes(i, l),
                this.indexes = [i, l]
            }
            this.moveIndexes = [r, h],
            this.range = l,
            this.resetAreaOffset(),
            this.el.show()
        }
        setEnd(t, e) {
            const {data: i} = this;
            this.range = i.calSelectedRangeByEnd(t, e),
            this.reset()
        }
        reset() {
            X.call(this, this.data.getSelectedRect())
        }
        showAutofill(t, e) {
            if (-1 === t && -1 === e)
                return;
            const {sri: i, sci: s, eri: l, eci: r} = this.range
              , [h,n] = [t, e]
              , o = i - t
              , c = l - t
              , a = r - e;
            if (s - e > 0)
                this.arange = new d(i,n,l,s - 1);
            else if (o > 0)
                this.arange = new d(h,s,i - 1,r);
            else if (a < 0)
                this.arange = new d(i,r + 1,l,n);
            else {
                if (!(c < 0))
                    return void (this.arange = null);
                this.arange = new d(l + 1,s,h,r)
            }
            if (null !== this.arange) {
                const t = this.data.getRect(this.arange);
                t.width += 2,
                t.height += 2;
                const {br: e, l: i, t: s, tl: l} = this;
                e.showAutofill(H.call(this, t)),
                i.showAutofill(_.call(this, t)),
                s.showAutofill(F.call(this, t)),
                l.showAutofill(t)
            }
        }
        hideAutofill() {
            ["br", "l", "t", "tl"].forEach(t=>{
                this[t].hideAutofill()
            }
            )
        }
        showClipboard() {
            const t = this.data.getClipboardRect();
            Y.call(this, t),
            ["br", "l", "t", "tl"].forEach(t=>{
                this[t].showClipboard()
            }
            )
        }
        hideClipboard() {
            ["br", "l", "t", "tl"].forEach(t=>{
                this[t].hideClipboard()
            }
            )
        }
    }
    function K(t) {
        t.preventDefault();
        const {filterItems: e} = this;
        e.length <= 0 || (t.stopPropagation(),
        e[this.itemIndex].el.click(),
        this.hide())
    }
    class q {
        constructor(t, e) {
            this.filterItems = [],
            this.items = t,
            this.el = l("div", `${D}-suggest`).hide(),
            this.itemClick = e,
            this.itemIndex = 0
        }
        setOffset(t) {
            this.el.cssRemoveKeys("top", "bottom").offset(t)
        }
        hide() {
            this.filterItems = [],
            this.itemIndex = 0,
            this.el.hide()
        }
        search(t) {
            let {items: e} = this;
            /^\s*$/.test(t) || (e = e.filter(e=>e.key.startsWith(t.toUpperCase()))),
            e = e.map(t=>{
                const e = l("div", `${D}-item`).child(t.key).on("click.stop", ()=>{
                    this.itemClick(t),
                    this.hide()
                }
                );
                return e.child(l("div", "label").html(t.title || t.label)),
                e
            }
            ),
            this.filterItems = e,
            e.length <= 0 || (e[0].toggle(),
            this.el.html("").children(...e).show())
        }
        bindInputEvents(t) {
            t.on("keydown", t=>(function(t) {
                const {keyCode: e} = t;
                switch (t.ctrlKey && t.stopPropagation(),
                e) {
                case 37:
                    t.stopPropagation();
                    break;
                case 38:
                    (function(t) {
                        t.preventDefault(),
                        t.stopPropagation();
                        const {filterItems: e} = this;
                        e.length <= 0 || (e[this.itemIndex].toggle(),
                        this.itemIndex -= 1,
                        this.itemIndex < 0 && (this.itemIndex = e.length - 1),
                        e[this.itemIndex].toggle())
                    }
                    ).call(this, t);
                    break;
                case 39:
                    t.stopPropagation();
                    break;
                case 40:
                    (function(t) {
                        t.stopPropagation();
                        const {filterItems: e} = this;
                        e.length <= 0 || (e[this.itemIndex].toggle(),
                        this.itemIndex += 1,
                        this.itemIndex > e.length - 1 && (this.itemIndex = 0),
                        e[this.itemIndex].toggle())
                    }
                    ).call(this, t);
                    break;
                case 13:
                case 9:
                    K.call(this, t);
                    break;
                default:
                    t.stopPropagation()
                }
            }
            ).call(this, t)),
            z(window, "click", t=>{
                this.el.contains(t.target) || this.hide()
            }
            )
        }
    }
    function G() {
        if (!/^\s*$/.test(this.inputText)) {
            const {textlineEl: t, textEl: e, areaOffset: i} = this
              , s = t.offset().width + 9
              , l = this.viewFn().width - i.left - 9;
            if (s > i.width) {
                let t = s;
                if (s > l) {
                    t = l;
                    let r = parseInt(s / l, 10);
                    r += s % l > 0 ? 1 : 0,
                    (r *= this.rowHeight) > i.height && e.css("height", `${r}px`)
                }
                e.css("width", `${t}px`)
            }
        }
    }
    function J(t, e) {
        const {textEl: i, textlineEl: s} = this;
        i.el.blur(),
        i.val(t),
        s.html(t),
        function(t) {
            const {el: e} = this.textEl;
            setTimeout(()=>{
                e.focus(),
                e.setSelectionRange(t, t)
            }
            , 0)
        }
        .call(this, e)
    }
    class Z {
        constructor(t, e, i) {
            this.viewFn = e,
            this.rowHeight = i,
            this.suggest = new q(t,t=>{
                (function(t) {
                    const {inputText: e} = this
                      , i = e.lastIndexOf("=")
                      , s = e.substring(0, i + 1);
                    let l = e.substring(i + 1);
                    l = -1 !== l.indexOf(")") ? l.substring(l.indexOf(")")) : "",
                    this.inputText = `${s + t.key}(`;
                    const r = this.inputText.length;
                    this.inputText += `)${l}`,
                    J.call(this, this.inputText, r)
                }
                ).call(this, t)
            }
            ),
            this.areaEl = l("div", `${D}-editor-area`).children(this.textEl = l("textarea", "").on("input", t=>(function(t) {
                const e = t.target.value;
                this.inputText = e;
                const i = e.lastIndexOf("=")
                  , {suggest: s, textlineEl: l} = this;
                -1 !== i ? s.search(e.substring(i + 1)) : s.hide(),
                l.html(e),
                G.call(this),
                this.change("input", e)
            }
            ).call(this, t)), this.textlineEl = l("div", "textline"), this.suggest.el).on("mousemove.stop", ()=>{}
            ).on("mousedown.stop", ()=>{}
            ),
            this.el = l("div", `${D}-editor`).child(this.areaEl).hide(),
            this.suggest.bindInputEvents(this.textEl),
            this.areaOffset = null,
            this.freeze = {
                w: 0,
                h: 0
            },
            this.cell = null,
            this.inputText = "",
            this.change = (()=>{}
            )
        }
        setFreezeLengths(t, e) {
            this.freeze.w = t,
            this.freeze.h = e
        }
        clear() {
            const {cell: t} = this;
            t && t.text;
            "" !== this.inputText && this.change("finished", this.inputText),
            this.cell = null,
            this.areaOffset = null,
            this.inputText = "",
            this.el.hide(),
            this.textEl.val(""),
            this.textlineEl.html("")
        }
        setOffset(t, e="top") {
            const {textEl: i, areaEl: s, suggest: l, freeze: r, el: h} = this;
            if (t) {
                this.areaOffset = t;
                const {left: n, top: o, width: c, height: a, l: d, t: f} = t
                  , u = {
                    left: 0,
                    top: 0
                };
                r.w > d && r.h > f || (r.w < d && r.h < f ? (u.left = r.w,
                u.top = r.h) : r.w > d ? u.top = r.h : r.h > f && (u.left = r.w)),
                h.offset(u),
                s.offset({
                    left: n - u.left - .8,
                    top: o - u.top - .8
                }),
                i.offset({
                    width: c - 9 + .8,
                    height: a - 3 + .8
                });
                const g = {
                    left: 0
                };
                g[e] = a,
                l.setOffset(g)
            }
        }
        setCell(t) {
            this.el.show(),
            this.cell = t;
            const e = t && t.text || "";
            this.inputText = e,
            J.call(this, e, e.length),
            G.call(this)
        }
    }
    const Q = [{
        key: "copy",
        title: "Copy",
        label: "Ctrl+C"
    }, {
        key: "cut",
        title: "Cut",
        label: "Ctrl+X"
    }, {
        key: "paste",
        title: "Paste",
        label: "Ctrl+V"
    }, {
        key: "paste-value",
        title: "Paste values only",
        label: "Ctrl+Shift+V"
    }, {
        key: "paste-format",
        title: "Paste format only",
        label: "Ctrl+Alt+V"
    }, {
        key: "divider"
    }, {
        key: "insert-row",
        title: "Insert row"
    }, {
        key: "insert-column",
        title: "Insert column"
    }, {
        key: "divider"
    }, {
        key: "delete-row",
        title: "Delete row"
    }, {
        key: "delete-column",
        title: "Delete column"
    }, {
        key: "delete-cell-text",
        title: "Delete cell"
    }];
    function tt() {
        return Q.map(t=>(function(t) {
            return "divider" === t.key ? l("div", `${D}-item divider`) : l("div", `${D}-item`).on("click", ()=>{
                this.itemClick(t.key),
                this.hide()
            }
            ).children(t.title, l("div", "label").child(t.label || ""))
        }
        ).call(this, t))
    }
    class et {
        constructor(t) {
            this.el = l("div", `${D}-contextmenu`).children(...tt.call(this)).hide(),
            this.viewFn = t,
            this.itemClick = (()=>{}
            ),
            z(window, "click", t=>{
                this.el.contains(t.target) || this.hide()
            }
            )
        }
        hide() {
            this.el.hide()
        }
        setPosition(t, e) {
            const {el: i} = this
              , {height: s, width: l} = i.show().offset()
              , r = this.viewFn();
            let h = e
              , n = t;
            r.height - e <= s && (h -= s - 1),
            r.width - t <= l && (n -= l - 1),
            i.offset({
                left: n,
                top: h
            })
        }
    }
    const it = [{
        key: "Helvetica",
        title: "Helvetica"
    }, {
        key: "Source Sans Pro",
        title: "Source Sans Pro"
    }, {
        key: "Comic Sans MS",
        title: "Comic Sans MS"
    }, {
        key: "Arial",
        title: "Arial"
    }, {
        key: "Courier New",
        title: "Courier New"
    }, {
        key: "Verdana",
        title: "Verdana"
    }]
      , st = [{
        pt: 7.5,
        px: 10
    }, {
        pt: 8,
        px: 11
    }, {
        pt: 9,
        px: 12
    }, {
        pt: 10,
        px: 13
    }, {
        pt: 10.5,
        px: 14
    }, {
        pt: 11,
        px: 15
    }, {
        pt: 12,
        px: 16
    }, {
        pt: 14,
        px: 18.7
    }, {
        pt: 15,
        px: 20
    }, {
        pt: 16,
        px: 21.3
    }, {
        pt: 18,
        px: 24
    }, {
        pt: 22,
        px: 29.3
    }, {
        pt: 24,
        px: 32
    }, {
        pt: 26,
        px: 34.7
    }, {
        pt: 36,
        px: 48
    }, {
        pt: 42,
        px: 56
    }];
    const lt = (t,e)=>{
        if (t[0] >= "0" && t[0] <= "9")
            return Number(t);
        if ('"' === t[0])
            return t.substring(1);
        const [i,s] = o(t);
        return e(i, s)
    }
      , rt = (t,e,i,s,l)=>{
        if ("=" === i[0]) {
            const r = (t=>{
                const e = []
                  , i = [];
                let s = []
                  , l = 0
                  , r = 1;
                for (let h = 0; h < t.length; h += 1) {
                    const n = t.charAt(h);
                    if (" " !== n)
                        if (n >= "a" && n <= "z")
                            s.push(n.toUpperCase());
                        else if (n >= "0" && n <= "9" || n >= "A" && n <= "Z" || "." === n)
                            s.push(n);
                        else if ('"' === n) {
                            for (h += 1; '"' !== t.charAt(h); )
                                s.push(t.charAt(h)),
                                h += 1;
                            i.push(`"${s.join("")}`),
                            s = []
                        } else {
                            if (s.length > 0 && i.push(s.join("")),
                            ")" === n) {
                                let t = e.pop();
                                if (2 === l) {
                                    const [e,s] = o(i.pop())
                                      , [l,r] = o(i.pop());
                                    let h = 0;
                                    for (let t = l; t <= e; t += 1)
                                        for (let e = r; e <= s; e += 1)
                                            i.push(a(t, e)),
                                            h += 1;
                                    i.push([t, h])
                                } else if (1 === l)
                                    i.push([t, r]),
                                    r = 1;
                                else
                                    for (; "(" !== t && e.length > 0; )
                                        i.push(t),
                                        t = e.pop();
                                l = 0
                            } else if (":" === n)
                                l = 2;
                            else if ("," === n)
                                l = 1,
                                r += 1;
                            else if ("(" === n && s.length > 0)
                                i.pop(),
                                e.push(s.join(""));
                            else {
                                if (e.length > 0 && ("+" === n || "-" === n)) {
                                    const t = e[e.length - 1];
                                    if ("*" === t || "/" === t)
                                        for (; e.length > 0; )
                                            i.push(e.pop())
                                }
                                e.push(n)
                            }
                            s = []
                        }
                }
                for (s.length > 0 && i.push(s.join("")); e.length > 0; )
                    i.push(e.pop());
                return i
            }
            )(i.substring(1));
            return r.length <= 0 ? i : ((t,e,i)=>{
                const s = [];
                for (let l = 0; l < t.length; l += 1)
                    if ("+" === t[l]) {
                        const t = s.pop()
                          , e = s.pop();
                        s.push(Number(e) + Number(t))
                    } else if ("-" === t[l]) {
                        const t = s.pop();
                        s.push(Number(s.pop()) - Number(t))
                    } else if ("*" === t[l])
                        s.push(Number(s.pop()) * Number(s.pop()));
                    else if ("/" === t[l]) {
                        const t = s.pop();
                        s.push(Number(s.pop()) / Number(t))
                    } else if (Array.isArray(t[l])) {
                        const [i,r] = t[l]
                          , h = [];
                        for (let t = 0; t < r; t += 1)
                            h.push(s.pop());
                        s.push(e[i].render(h))
                    } else
                        s.push(lt(t[l], i));
                return s[0]
            }
            )(r, s, (i,r)=>{
                const h = t === r && e === i ? 0 : l(i, r);
                return rt(t, e, h, s, l)
            }
            )
        }
        return i
    }
    ;
    var ht = {
        render: rt
    };
    const nt = [{
        key: "SUM",
        title: "求和",
        render: t=>t.reduce((t,e)=>Number(t) + Number(e), 0)
    }, {
        key: "AVERAGE",
        title: "求平均值",
        render: t=>t.reduce((t,e)=>Number(t) + Number(e), 0) / t.length
    }, {
        key: "MAX",
        title: "最大值",
        render: t=>Math.max(...t.map(t=>Number(t)))
    }, {
        key: "MIN",
        title: "最小值",
        render: t=>Math.min(...t.map(t=>Number(t)))
    }, {
        key: "CONCAT",
        title: "字符串拼接",
        render: t=>t.join("")
    }]
      , ot = nt
      , ct = {};
    nt.forEach(t=>{
        ct[t.key] = t
    }
    );
    const at = t=>t
      , dt = t=>{
        if (/^(-?\d*.?\d*)$/.test(t)) {
            const e = Number(t).toFixed(2).toString()
              , [i,...s] = e.split("\\.");
            return [i.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"), ...s]
        }
        return t
    }
      , ft = [{
        key: "normal",
        title: "Normal",
        type: "string",
        render: at
    }, {
        key: "text",
        title: "Plain Text",
        type: "string",
        render: at
    }, {
        key: "number",
        title: "Number",
        type: "number",
        label: "1,000.12",
        render: dt
    }, {
        key: "percent",
        title: "Percent",
        type: "number",
        label: "10.12%",
        render: t=>`${t}%`
    }, {
        key: "rmb",
        title: "RMB",
        type: "number",
        label: "￥10.00",
        render: t=>`￥${dt(t)}`
    }, {
        key: "usd",
        title: "USD",
        type: "number",
        label: "$10.00",
        render: t=>`$${dt(t)}`
    }, {
        key: "date",
        title: "Date",
        type: "date",
        label: "26/09/2008",
        render: at
    }, {
        key: "time",
        title: "Time",
        type: "date",
        label: "15:59:00",
        render: at
    }, {
        key: "datetime",
        title: "Date time",
        type: "date",
        label: "26/09/2008 15:59:00",
        render: at
    }, {
        key: "duration",
        title: "Duration",
        type: "date",
        label: "24:01:00",
        render: at
    }]
      , ut = {};
    function gt() {
        return window.devicePixelRatio || 1
    }
    function pt() {
        return gt() - .5
    }
    function mt(t) {
        return parseInt(t * gt(), 10)
    }
    ft.forEach(t=>{
        ut[t.key] = t
    }
    );
    class wt {
        constructor(t, e, i, s, l=0) {
            this.x = t,
            this.y = e,
            this.width = i,
            this.height = s,
            this.padding = l,
            this.bgcolor = "#ffffff",
            this.borderTop = null,
            this.borderRight = null,
            this.borderBottom = null,
            this.borderLeft = null
        }
        setBorders({top: t, bottom: e, left: i, right: s}) {
            t && (this.borderTop = t),
            s && (this.borderRight = s),
            e && (this.borderBottom = e),
            i && (this.borderLeft = i)
        }
        innerWidth() {
            return this.width - 2 * this.padding
        }
        innerHeight() {
            return this.height - 2 * this.padding
        }
        textx(t) {
            const {width: e, padding: i} = this;
            let {x: s} = this;
            return "left" === t ? s += i : "center" === t ? s += e / 2 : "right" === t && (s += e - i),
            s
        }
        texty(t, e, i) {
            const {height: s, padding: l} = this;
            let {y: r} = this;
            if ("top" === t)
                r += l;
            else if ("middle" === t) {
                const t = r + s / 2 - i
                  , h = r + l + e / 2 + 1;
                r = t < h ? h : t
            } else
                "bottom" === t && (r += s - 2 * i - l);
            return r
        }
        topxys() {
            const {x: t, y: e, width: i} = this;
            return [[t, e], [t + i, e]]
        }
        rightxys() {
            const {x: t, y: e, width: i, height: s} = this;
            return [[t + i, e], [t + i, e + s]]
        }
        bottomxys() {
            const {x: t, y: e, width: i, height: s} = this;
            return [[t, e + s], [t + i, e + s]]
        }
        leftxys() {
            const {x: t, y: e, height: i} = this;
            return [[t, e], [t, e + i]]
        }
    }
    function bt(t, e, i, s, l, r, h) {
        const n = {
            x: 0,
            y: 0
        };
        "underline" === t ? n.y = "bottom" === l ? 0 : "top" === l ? -(r + 2) : -r / 2 : "strike" === t && ("bottom" === l ? n.y = r / 2 : "top" === l && (n.y = -(r / 2 + 2))),
        "center" === s ? n.x = h / 2 : "right" === s && (n.x = h),
        this.line([e - n.x, i - n.y], [e - n.x + h, i - n.y])
    }
    class yt {
        constructor(t, e, i) {
            this.el = t,
            this.ctx = t.getContext("2d"),
            this.resize(e, i),
            this.ctx.scale(gt(), gt())
        }
        resize(t, e) {
            this.el.style.width = `${t}px`,
            this.el.style.height = `${e}px`,
            this.el.width = mt(t),
            this.el.height = mt(e)
        }
        clear() {
            const {width: t, height: e} = this.el;
            return this.ctx.clearRect(0, 0, t, e),
            this
        }
        attr(t) {
            return Object.assign(this.ctx, t),
            this
        }
        save() {
            return this.ctx.save(),
            this.ctx.beginPath(),
            this
        }
        restore() {
            return this.ctx.restore(),
            this
        }
        beginPath() {
            return this.ctx.beginPath(),
            this
        }
        translate(t, e) {
            return this.ctx.translate(mt(t), mt(e)),
            this
        }
        fillRect(t, e, i, s) {
            return this.ctx.fillRect(mt(t) - .5, mt(e) - .5, mt(i), mt(s)),
            this
        }
        fillText(t, e, i) {
            return this.ctx.fillText(t, mt(e), mt(i)),
            this
        }
        text(t, e, i={}, s=!0) {
            const {ctx: l} = this
              , {align: r, valign: h, font: n, color: o, strike: c, underline: a} = i
              , d = e.textx(r);
            l.save(),
            this.attr({
                textAlign: r,
                textBaseline: h,
                font: `${n.italic ? "italic" : ""} ${n.bold ? "bold" : ""} ${mt(n.size)}px ${n.name}`,
                fillStyle: o,
                strokeStyle: o
            });
            const f = l.measureText(t).width;
            let u = 0;
            if (s) {
                u = (Math.ceil(f / e.innerWidth()) - 1) * n.size / 2
            }
            let g = e.texty(h, n.size, u);
            if (s && f > e.innerWidth()) {
                const i = {
                    len: 0,
                    start: 0
                };
                for (let s = 0; s < t.length; s += 1)
                    i.len >= e.innerWidth() && (this.fillText(t.substring(i.start, s), d, g),
                    c && bt.call(this, "strike", d, g, r, h, n.size, i.len),
                    a && bt.call(this, "underline", d, g, r, h, n.size, i.len),
                    g += n.size + 2,
                    i.len = 0,
                    i.start = s),
                    i.len += l.measureText(t[s]).width;
                s && i.len > 0 && (this.fillText(t.substring(i.start), d, g),
                c && bt.call(this, "strike", d, g, r, h, n.size, i.len),
                a && bt.call(this, "underline", d, g, r, h, n.size, i.len))
            } else
                this.fillText(t, d, g),
                c && bt.call(this, "striket", d, g, r, h, n.size, f),
                a && bt.call(this, "underline", d, g, r, h, n.size, f);
            return l.restore(),
            this
        }
        border(t, e) {
            const {ctx: i} = this;
            return i.lineWidth = pt,
            i.strokeStyle = e,
            "medium" === t ? i.lineWidth = mt(1) + .5 : "thick" === t ? i.lineWidth = mt(2) : "dashed" === t ? i.setLineDash([mt(3), mt(2)]) : "dotted" === t ? i.setLineDash([mt(1), mt(1)]) : "double" === t && i.setLineDash([mt(2), 0]),
            this
        }
        line(...t) {
            const {ctx: e} = this;
            if (t.length > 1) {
                const [i,s] = t[0];
                e.moveTo(mt(i) - .5, mt(s) - .5);
                for (let i = 1; i < t.length; i += 1) {
                    const [s,l] = t[i];
                    e.lineTo(mt(s) - .5, mt(l) - .5)
                }
                e.stroke()
            }
            return this
        }
        strokeBorders(t) {
            const {ctx: e} = this;
            e.save(),
            e.beginPath();
            const {borderTop: i, borderRight: s, borderBottom: l, borderLeft: r} = t;
            i && (this.border(...i),
            this.line(...t.topxys())),
            s && (this.border(...s),
            this.line(...t.rightxys())),
            l && (this.border(...l),
            this.line(...t.bottomxys())),
            r && (this.border(...r),
            this.line(...t.leftxys())),
            e.restore()
        }
        rect(t, e) {
            const {ctx: i} = this
              , {x: s, y: l, width: r, height: h, bgcolor: n} = t;
            i.save(),
            i.beginPath(),
            i.fillStyle = n || "#fff",
            i.rect(mt(s) - .5, mt(l) - .5, mt(r), mt(h)),
            i.clip(),
            i.fill(),
            this.strokeBorders(t),
            e(),
            i.restore()
        }
    }
    const vt = 5
      , xt = {
        fillStyle: "#f4f5f8"
    }
      , Ct = {
        fillStyle: "#fff",
        lineWidth: pt,
        strokeStyle: "#e6e6e6"
    };
    function kt(t, e) {
        const {draw: i, data: s} = this
          , l = s.getCell(t, e)
          , r = s.getCellStyleOrDefault(t, e)
          , h = function(t, e) {
            const {data: i} = this
              , {left: s, top: l, width: r, height: h} = i.cellRect(t, e);
            return new wt(s,l,r,h,vt)
        }
        .call(this, t, e);
        h.bgcolor = r.bgcolor,
        void 0 !== r.border && h.setBorders(r.border),
        i.rect(h, ()=>{
            if (null !== l) {
                let n = ht.render(t, e, l.text || "", ct, (t,e)=>s.getCellTextOrDefault(e, t));
                r.format && (n = ut[r.format].render(n));
                const o = Object.assign({}, r.font);
                o.size = function(t) {
                    for (let e = 0; e < st.length; e += 1) {
                        const i = st[e];
                        if (i.pt === t)
                            return i.px
                    }
                    return t
                }(o.size),
                i.text(n, h, {
                    align: r.align,
                    valign: r.valign,
                    font: o,
                    color: r.color,
                    strike: r.strike,
                    underline: r.underline
                }, r.textwrap)
            }
        }
        )
    }
    function Et({sri: t, sci: e, eri: i, eci: s}, l) {
        const {draw: r, data: h} = this
          , {cols: n, rows: o} = h;
        r.save(),
        r.translate(n.indexWidth, o.height).translate(-l.x, -l.y);
        const c = new d(t,e,i - 1,s - 1);
        c.each((t,e)=>{
            kt.call(this, t, e)
        }
        ),
        h.eachMergesInView(c, t=>{
            kt.call(this, t.sri, t.sci)
        }
        ),
        r.restore()
    }
    function St(t, e, i, s) {
        const {draw: l} = this;
        l.save(),
        l.attr({
            fillStyle: "rgba(75, 137, 255, 0.08)"
        }).fillRect(t, e, i, s),
        l.restore()
    }
    function zt(t) {
        const {draw: e, data: i} = this
          , {cols: s, rows: l} = i;
        e.save();
        const r = l.sumHeight(t.sri, t.eri) + l.height
          , n = s.sumWidth(t.sci, t.eci) + s.indexWidth;
        e.attr(xt).fillRect(0, 0, s.indexWidth, r).fillRect(0, 0, n, l.height);
        const {sri: o, sci: c, eri: a, eci: d} = i.selector.range;
        e.attr({
            textAlign: "center",
            textBaseline: "middle",
            font: `500 ${mt(12)}px Source Sans Pro`,
            fillStyle: "#585757",
            lineWidth: pt(),
            strokeStyle: "#e6e6e6"
        }),
        i.rowEach(t.sri, t.eri, (i,r,h)=>{
            const n = r + l.height;
            e.line([0, n], [s.indexWidth, n]),
            i !== t.eri && (o <= i && i < a + 1 && St.call(this, 0, n, s.indexWidth, h),
            e.fillText(i + 1, s.indexWidth / 2, n + h / 2))
        }
        ),
        e.line([s.indexWidth, 0], [s.indexWidth, r]),
        i.colEach(t.sci, t.eci, (i,r,n)=>{
            const o = r + s.indexWidth;
            e.line([o, 0], [o, l.height]),
            i !== t.eci && (c <= i && i < d + 1 && St.call(this, o, 0, n, l.height),
            e.fillText(h(i), o + n / 2, l.height / 2))
        }
        ),
        e.line([0, l.height], [n, l.height]),
        e.attr({
            fillStyle: "#f4f5f8"
        }).fillRect(0, 0, s.indexWidth, l.height).line([s.indexWidth, 0], [s.indexWidth, l.height]).line([0, l.height], [s.indexWidth, l.height]),
        e.restore()
    }
    function Tt({sri: t, sci: e, eri: i, eci: s}, l={
        x: 0,
        y: 0
    }) {
        const {draw: r, data: h} = this
          , {cols: n, rows: o, settings: c} = h;
        if (!c.showGrid)
            return;
        r.save(),
        r.attr(Ct).translate(n.indexWidth, o.height).translate(l.x, l.y);
        const a = n.sumWidth(e, s)
          , d = o.sumHeight(t, i);
        r.fillRect(0, 0, a, d),
        h.rowEach(t, i, (t,e)=>{
            r.line([0, e], [a, e])
        }
        ),
        h.colEach(e, s, (t,e)=>{
            r.line([e, 0], [e, d])
        }
        ),
        r.restore()
    }
    function $t(t, e) {
        const {draw: i, data: s} = this
          , {rows: l, cols: r} = s;
        i.save().translate(r.indexWidth, l.height).attr({
            strokeStyle: "rgba(75, 137, 255, .6)"
        }),
        i.line(t, e),
        i.restore()
    }
    function Ot(t, e) {
        Tt.call(this, t),
        Et.call(this, t, e),
        zt.call(this, t)
    }
    var Dt = class {
        constructor(t, e) {
            this.el = t,
            this.draw = new yt(t,e.viewWidth(),e.viewHeight()),
            this.data = e
        }
        render() {
            const {data: t} = this;
            this.draw.resize(t.viewWidth(), t.viewHeight()),
            this.clear();
            const e = t.viewRange();
            Ot.call(this, t.viewRange(), t.scroll);
            const [i,s] = t.freeze;
            (i > 0 || s > 0) && (function({eri: t, eci: e}) {
                const {data: i} = this
                  , [s,l] = i.freeze
                  , {scroll: r, cols: h, rows: n} = i
                  , o = n.sumHeight(0, s)
                  , c = i.viewWidth()
                  , a = i.freezeTotalWidth()
                  , f = i.freezeTotalHeight();
                s > 0 && (Tt.call(this, new d(0,l + i.scroll.ci,s,e), {
                    x: a,
                    y: 0
                }),
                Et.call(this, new d(0,l,s,e), {
                    x: r.x,
                    y: 0
                }));
                const u = i.viewHeight()
                  , g = h.sumWidth(0, l);
                l > 0 && (Tt.call(this, new d(s + i.scroll.ri,0,t,l), {
                    x: 0,
                    y: f
                }),
                Et.call(this, new d(s,0,t,l), {
                    x: 0,
                    y: r.y
                })),
                $t.call(this, [0, o], [c, o]),
                $t.call(this, [g, 0], [g, u])
            }
            .call(this, e),
            Ot.call(this, t.freezeViewRange(), {
                x: 0,
                y: 0
            }))
        }
        clear() {
            this.draw.clear()
        }
    }
    ;
    class Wt extends s {
        constructor(t, e, i, s, ...r) {
            super("div", `${D}-dropdown ${s}`),
            this.title = t,
            this.change = (()=>{}
            ),
            "string" == typeof t ? this.title = l("div", `${D}-dropdown-title`).child(t) : i && this.title.addClass("arrow-left"),
            this.contentEl = l("div", `${D}-dropdown-content`).children(...r).css("width", e).hide(),
            this.headerEl = l("div", `${D}-dropdown-header`),
            this.headerEl.on("click", ()=>{
                "block" !== this.contentEl.css("display") ? this.show() : this.hide()
            }
            ).children(this.title, i ? l("div", `${D}-icon arrow-right`).child(l("div", `${D}-icon-img arrow-down`)) : ""),
            this.children(this.headerEl, this.contentEl),
            z(window, "click", t=>{
                this.el.contains(t.target) || this.hide()
            }
            )
        }
        setTitle(t) {
            this.title.html(t),
            this.hide()
        }
        show() {
            this.contentEl.show(),
            this.parent().active()
        }
        hide() {
            this.parent().active(!1),
            this.contentEl.hide()
        }
    }
    class Rt extends Wt {
        constructor() {
            const t = it.map(t=>l("div", `${D}-item`).on("click", ()=>{
                this.setTitle(t.title),
                this.change(t)
            }
            ).child(t.title));
            super(it[0].title, "160px", !0, "bottom-left", ...t)
        }
    }
    class At extends Wt {
        constructor() {
            super("10", "60px", !0, "bottom-left", ...st.map(t=>l("div", `${D}-item`).on("click", ()=>{
                this.setTitle(`${t.pt}`),
                this.change(t)
            }
            ).child(`${t.pt}`)))
        }
    }
    class It extends Wt {
        constructor() {
            let t = ft.slice(0);
            t.splice(2, 0, {
                key: "divider"
            }),
            t.splice(7, 0, {
                key: "divider"
            }),
            super("Normal", "220px", !0, "bottom-left", ...t = t.map(t=>{
                const e = l("div", `${D}-item`);
                return "divider" === t.key ? e.addClass("divider") : (e.child(t.title).on("click", ()=>{
                    this.setTitle(t.title),
                    this.change(t)
                }
                ),
                t.label && e.child(l("div", "label").html(t.label))),
                e
            }
            ))
        }
        setTitle(t) {
            for (let e = 0; e < ft.length; e += 1)
                ft[e].key === t && this.title.html(ft[e].title);
            this.hide()
        }
    }
    class Nt extends s {
        constructor(t) {
            super("div", `${D}-icon`),
            this.iconNameEl = l("div", `${D}-icon-img ${t}`),
            this.child(this.iconNameEl)
        }
        setName(t) {
            this.iconNameEl.className(`${D}-icon-img ${t}`)
        }
    }
    class Ht extends Wt {
        constructor() {
            const t = nt.map(t=>l("div", `${D}-item`).on("click", ()=>{
                this.hide(),
                this.change(t)
            }
            ).child(t.key));
            super(new Nt("formula"), "180px", !0, "bottom-left", ...t)
        }
    }
    const Ft = ["#ffffff", "#000100", "#e7e5e6", "#445569", "#5b9cd6", "#ed7d31", "#a5a5a5", "#ffc001", "#4371c6", "#71ae47"]
      , _t = [["#f2f2f2", "#7f7f7f", "#d0cecf", "#d5dce4", "#deeaf6", "#fce5d5", "#ededed", "#fff2cd", "#d9e2f3", "#e3efd9"], ["#d8d8d8", "#595959", "#afabac", "#adb8ca", "#bdd7ee", "#f7ccac", "#dbdbdb", "#ffe59a", "#b3c6e7", "#c5e0b3"], ["#bfbfbf", "#3f3f3f", "#756f6f", "#8596b0", "#9cc2e6", "#f4b184", "#c9c9c9", "#fed964", "#8eaada", "#a7d08c"], ["#a5a5a5", "#262626", "#3a3839", "#333f4f", "#2e75b5", "#c45a10", "#7b7b7b", "#bf8e01", "#2f5596", "#538136"], ["#7f7f7f", "#0c0c0c", "#171516", "#222a35", "#1f4e7a", "#843c0a", "#525252", "#7e6000", "#203864", "#365624"]]
      , Pt = ["#c00000", "#fe0000", "#fdc101", "#ffff01", "#93d051", "#00b04e", "#01b0f1", "#0170c1", "#012060", "#7030a0"];
    function Mt(t) {
        return l("td", "").child(l("div", `${D}-color-palette-cell`).on("click.stop", ()=>this.change(t)).css("background-color", t))
    }
    class Bt {
        constructor() {
            this.el = l("div", `${D}-color-palette`),
            this.change = (()=>{}
            );
            const t = l("table", "").children(l("tbody", "").children(l("tr", `${D}-theme-color-placeholders`).children(...Ft.map(t=>Mt.call(this, t))), ..._t.map(t=>l("tr", `${D}-theme-colors`).children(...t.map(t=>Mt.call(this, t)))), l("tr", `${D}-standard-colors`).children(...Pt.map(t=>Mt.call(this, t)))));
            this.el.child(t)
        }
    }
    class jt extends Wt {
        constructor(t, e) {
            const i = new Nt(t).css("height", "16px").css("border-bottom", `3px solid ${e}`)
              , s = new Bt;
            s.change = (t=>{
                this.setTitle(t),
                this.change(t)
            }
            ),
            super(i, "auto", !1, "bottom-left", s.el)
        }
        setTitle(t) {
            this.title.css("border-color", t),
            this.hide()
        }
    }
    class Lt extends Wt {
        constructor(t, e) {
            super(new Nt(`align-${e}`), "auto", !0, "bottom-left", ...t.map(t=>(function(t) {
                return l("div", `${D}-item`).child(new Nt(t))
            }
            )(`align-${t}`).on("click", ()=>{
                this.setTitle(t),
                this.change(t)
            }
            )))
        }
        setTitle(t) {
            this.title.setName(`align-${t}`),
            this.hide()
        }
    }
    const Ut = [
        ["thin", '<svg xmlns="excelIcon.svg" width="50" height="1" style="user-select: none;"><line x1="0" y1="0.5" x2="50" y2="0.5" stroke-width="1" stroke="black" style="user-select: none;"></line></svg>'], 
        ["medium", '<svg xmlns="excelIcon.svg" width="50" height="2" style="user-select: none;"><line x1="0" y1="1.0" x2="50" y2="1.0" stroke-width="2" stroke="black" style="user-select: none;"></line></svg>'], 
        ["thick", '<svg xmlns="excelIcon.svg" width="50" height="3" style="user-select: none;"><line x1="0" y1="1.5" x2="50" y2="1.5" stroke-width="3" stroke="black" style="user-select: none;"></line></svg>'], 
        ["dashed", '<svg xmlns="excelIcon.svg" width="50" height="1" style="user-select: none;"><line x1="0" y1="0.5" x2="50" y2="0.5" stroke-width="1" stroke="black" stroke-dasharray="2" style="user-select: none;"></line></svg>'], 
        ["dotted", '<svg xmlns="excelIcon.svg" width="50" height="1" style="user-select: none;"><line x1="0" y1="0.5" x2="50" y2="0.5" stroke-width="1" stroke="black" stroke-dasharray="1" style="user-select: none;"></line></svg>']
    ];
    class Xt extends Wt {
        constructor(t) {
            const e = new Nt("line-type");
            let i = 0;
            const s = Ut.map((e,r)=>l("div", `${D}-item state ${t === e[0] ? "checked" : ""}`).on("click", ()=>{
                s[i].toggle("checked"),
                s[r].toggle("checked"),
                i = r,
                this.hide(),
                this.change(e)
            }
            ).child(l("div", `${D}-line-type`).html(e[1])));
            super(e, "auto", !1, "bottom-left", ...s)
        }
    }
    function Yt(...t) {
        return l("table", "").child(l("tbody", "").children(...t))
    }
    function Vt(t) {
        return l("td", "").child(l("div", `${D}-border-palette-cell`).child(new Nt(`border-${t}`)).on("click", ()=>{
            this.mode = t;
            const {mode: e, style: i, color: s} = this;
            this.change({
                mode: e,
                style: i,
                color: s
            })
        }
        ))
    }
    class Kt {
        constructor() {
            this.color = "#000",
            this.style = "thin",
            this.mode = "all",
            this.change = (()=>{}),
            this.ddColor = new jt("line-color",this.color),
            this.ddColor.change = (t=>{
                this.color = t
            }),
            this.ddType = new Xt(this.style),
            this.ddType.change = (([t])=>{
                this.style = t
            }),
            this.el = l("div", `${D}-border-palette`);
            const t = Yt(l("tr", "")
                .children(l("td", `${D}-border-palette-left`)
                    .child( Yt( l("tr", "")
                        .children(...["all", "inside", "horizontal", "vertical", "outside"]
                            .map( t=>Vt.call(this, t))
                        ), 
                        l("tr", "")
                            .children(...["left", "top", "right", "bottom", "none"]
                            .map( t=>Vt.call(this, t) )
                    ))), 
                    l("td", `${D}-border-palette-right`)
                    .children(l("div", `${D}-toolbar-btn`)
                        .child(this.ddColor.el), 
                        l("div", `${D}-toolbar-btn`)
                        .child(this.ddType.el)
                    )
                )
            );
            this.el.child(t)
        }
    }
    class qt extends Wt {
        constructor() {
            const t = new Nt("border-all")
              , e = new Kt;
            e.change = (t=>{
                this.change(t),
                this.hide()
            }
            ),
            super(t, "auto", !1, "bottom-left", e.el)
        }
    }
    function Gt(t) {
        return l("div", `${D}-toolbar-btn`).on("mouseenter", e=>{
            !function(t, e) {
                if (e.classList.contains("active"))
                    return;
                const {left: i, top: s, width: r, height: h} = e.getBoundingClientRect()
                  , n = l("div", `${D}-tooltip`).html(t).show();
                document.body.appendChild(n.el);
                const o = n.box();
                n.css("left", `${i + r / 2 - o.width / 2}px`).css("top", `${s + h + 2}px`),
                z(e, "mouseleave", ()=>{
                    document.body.contains(n.el) && document.body.removeChild(n.el)
                }
                ),
                z(e, "click", ()=>{
                    document.body.contains(n.el) && document.body.removeChild(n.el)
                }
                )
            }(t, e.target)
        }
        ).attr("data-tooltip", t)
    }
    function Jt() {
        return l("div", `${D}-toolbar-divider`)
    }
    function Zt(t, e, i=(()=>{}
    )) {
        return Gt(t).child(function(t) {
            return new Nt(t)
        }(e)).on("click", ()=>i())
    }
    function Qt(t) {
        let e = t;
        const i = t.split("-");
        i.length > 1 && i.forEach((t,i)=>{
            0 === i ? e = t : e += t[0].toUpperCase() + t.substring(1)
        }
        );
        const s = this[`${e}El`];
        s.toggle(),
        this.change(t, s.hasClass("active"))
    }
    class te extends Wt {
        constructor() {
            const t = new Nt("ellipsis")
              , e = l("div", `${D}-toolbar-more`);
            super(t, "auto", !1, "bottom-right", e),
            this.moreBtns = e,
            this.contentEl.css("max-width", "420px")
        }
    }
    function ee() {
        const {el: t, btns: e, moreEl: i, ddMore: s, btnChildren: l} = this
          , {moreBtns: r, contentEl: h} = s
          , n = t.box();
        let o = 160
          , c = 12;
        const a = []
          , d = [];
        l.forEach(t=>{
            const e = t.box();
            if (o += e.width,
            "More" === t.attr("data-tooltip") || o < n.width)
                a.push(t);
            else {
                const {marginLeft: i, marginRight: s} = t.computedStyle();
                c += e.width + parseInt(i, 10) + parseInt(s, 10),
                d.push(t)
            }
        }
        ),
        e.html("").children(...a),
        r.html("").children(...d),
        h.css("width", `${c}px`),
        d.length > 0 ? i.show() : i.hide()
    }
    class ie {
        constructor(t, e=!1) {
            this.data = t,
            this.change = (()=>{}
            );
            const i = t.defaultStyle();
            this.ddFormat = new It,
            this.ddFont = new Rt,
            this.ddFormula = new Ht,
            this.ddFontSize = new At,
            this.ddTextColor = new jt("text-color",i.color),
            this.ddFillColor = new jt("fill-color",i.bgcolor),
            this.ddAlign = new Lt(["left", "center", "right"],i.align),
            this.ddVAlign = new Lt(["top", "middle", "bottom"],i.valign),
            this.ddBorder = new qt,
            this.ddMore = new te,
            this.btnChildren = [
                this.undoEl = Zt("Undo (Ctrl+Z)", "undo", ()=>this.change("undo")), 
                this.redoEl = Zt("Redo (Ctrl+Y)", "redo", ()=>this.change("redo")), 
                this.paintformatEl = Zt("Paint format", "paintformat", ()=>Qt.call(this, "paintformat")), 
                this.clearformatEl = Zt("Clear format", "clearformat", ()=>this.change("clearformat")), 
                    Jt(), 
                    Gt("Format").child(this.ddFormat.el), 
                    Jt(), 
                    Gt("Font").child(this.ddFont.el), 
                    Gt("Font size").child(this.ddFontSize.el), 
                    Jt(), 
                this.fontBoldEl = Zt("Bold (Ctrl+B)", "bold", ()=>Qt.call(this, "font-bold")), 
                this.fontItalicEl = Zt("Italic (Ctrl+I)", "italic", ()=>Qt.call(this, "font-italic")), 
                this.underlineEl = Zt("Underline (Ctrl+U)", "underline", ()=>Qt.call(this, "underline")), 
                this.striketEl = Zt("Strike", "strike", ()=>Qt.call(this, "strike")), 
                    Gt("Text color").child(this.ddTextColor.el), 
                    Jt(), 
                    Gt("Fill color").child(this.ddFillColor.el), 
                    Gt("Borders").child(this.ddBorder.el), 
                this.mergeEl = Zt("Merge cells", "merge", ()=>Qt.call(this, "merge")), 
                    Jt(), 
                    Gt("Horizontal align").child(this.ddAlign.el), 
                    Gt("Vertical align").child(this.ddVAlign.el), 
                this.textwrapEl = Zt("Text wrapping", "textwrap", ()=>Qt.call(this, "textwrap")), 
                    Jt(), 
                this.freezeEl = Zt("Freeze cell", "freeze", ()=>Qt.call(this, "freeze")), 
                    Gt("Functions").child(this.ddFormula.el), 
                this.moreEl = Gt("More").child(this.ddMore.el).hide()
            ],
            this.el = l("div", `${D}-toolbar`),
            this.btns = l("div", `${D}-toolbar-btns`).children(...this.btnChildren),
            this.el.child(this.btns),
            e && this.el.hide(),
            function() {
                this.ddFormat.change = (t=>this.change("format", t.key)),
                this.ddFont.change = (t=>this.change("font-name", t.key)),
                this.ddFormula.change = (t=>this.change("formula", t.key)),
                this.ddFontSize.change = (t=>this.change("font-size", t.pt)),
                this.ddTextColor.change = (t=>this.change("color", t)),
                this.ddFillColor.change = (t=>this.change("bgcolor", t)),
                this.ddAlign.change = (t=>this.change("align", t)),
                this.ddVAlign.change = (t=>this.change("valign", t)),
                this.ddBorder.change = (t=>this.change("border", t))
            }
            .call(this),
            this.reset(),
            setTimeout(()=>{
                ee.call(this)
            }, 0),
            z(window, "resize", ()=>{
                ee.call(this)
            })
        }
        paintformatActive() {
            return this.paintformatEl.hasClass("active")
        }
        paintformatToggle() {
            this.paintformatEl.toggle()
        }
        trigger(t) {
            Qt.call(this, t)
        }
        reset() {
            const {data: t} = this
              , e = t.getSelectedCellStyle()
              , i = t.getSelectedCell();
            this.undoEl.disabled(!t.canUndo()),
            this.redoEl.disabled(!t.canRedo()),
            this.mergeEl.active(t.canUnmerge()).disabled(!t.selector.multiple());
            const {font: s} = e;
            this.ddFont.setTitle(s.name),
            this.ddFontSize.setTitle(s.size),
            this.fontBoldEl.active(s.bold),
            this.fontItalicEl.active(s.italic),
            this.underlineEl.active(e.underline),
            this.striketEl.active(e.strike),
            this.ddTextColor.setTitle(e.color),
            this.ddFillColor.setTitle(e.bgcolor),
            this.ddAlign.setTitle(e.align),
            this.ddVAlign.setTitle(e.valign),
            this.textwrapEl.active(e.textwrap),
            this.freezeEl.active(t.freezeIsActive()),
            i && i.format && this.ddFormat.setTitle(i.format)
        }
    }
    function se(t, e, i, s=!0) {
        if (-1 === e && -1 === i)
            return;
        const {table: l, selector: r, toolbar: h} = this;
        t ? r.setEnd(e, i) : r.set(e, i, s),
        h.reset(),
        l.render()
    }
    function le(t, e) {
        const {selector: i, data: s} = this
          , {rows: l, cols: r} = s;
        let[h,n] = i.indexes;
        const {eri: o, eci: c} = i.range;
        t && ([h,n] = i.moveIndexes),
        "left" === e ? n > 0 && (n -= 1) : "right" === e ? (c !== n && (n = c),
        n < r.len - 1 && (n += 1)) : "up" === e ? h > 0 && (h -= 1) : "down" === e ? (o !== h && (h = o),
        h < l.len - 1 && (h += 1)) : "row-first" === e ? n = 0 : "row-last" === e ? n = r.len - 1 : "col-first" === e ? h = 0 : "col-last" === e && (h = l.len - 1),
        t && (i.moveIndexes = [h, n]),
        se.call(this, t, h, n),
        function() {
            const {data: t, verticalScrollbar: e, horizontalScrollbar: i} = this
              , {l: s, t: l, left: r, top: h, width: n, height: o} = t.getSelectedRect()
              , c = this.getTableOffset();
            if (Math.abs(r) + n > c.width)
                i.move({
                    left: s + n - c.width
                });
            else {
                const e = t.freezeTotalWidth();
                r < e && i.move({
                    left: s - 1 - e
                })
            }
            if (Math.abs(h) + o > c.height)
                e.move({
                    top: l + o - c.height - 1
                });
            else {
                const i = t.freezeTotalHeight();
                h < i && e.move({
                    top: l - 1 - i
                })
            }
        }
        .call(this)
    }
    function re() {
        const {data: t, verticalScrollbar: e} = this
          , {height: i} = this.getTableOffset();
        e.set(i, t.rows.totalHeight())
    }
    function he() {
        const {data: t, horizontalScrollbar: e} = this
          , {width: i} = this.getTableOffset();
        t && e.set(i, t.cols.totalWidth())
    }
    function ne() {
        const {tableEl: t, overlayerEl: e, overlayerCEl: i, table: s, toolbar: l, selector: r} = this
          , h = this.getTableOffset()
          , n = this.getRect();
        t.attr(n),
        e.offset(n),
        i.offset(h),
        re.call(this),
        he.call(this),
        function() {
            const {selector: t, data: e, editor: i} = this
              , [s,l] = e.freeze;
            if (s > 0 || l > 0) {
                const t = e.freezeTotalWidth()
                  , s = e.freezeTotalHeight();
                i.setFreezeLengths(t, s)
            }
            t.resetAreaOffset()
        }
        .call(this),
        s.render(),
        l.reset(),
        r.reset()
    }
    function oe() {
        const {data: t, selector: e} = this;
        t.clearClipboard(),
        e.hideClipboard()
    }
    function ce() {
        const {data: t, selector: e} = this;
        t.copy(),
        e.showClipboard()
    }
    function ae() {
        const {data: t, selector: e} = this;
        t.cut(),
        e.showClipboard()
    }
    function de(t) {
        this.data.paste(t),
        ne.call(this)
    }
    function fe(t) {
        const {selector: e, data: i, table: s} = this
          , l = t.target.className === `${D}-selector-corner`;
        let {ri: r, ci: h} = i.getCellRectByXY(t.offsetX, t.offsetY);
        t.shiftKey || (l ? e.showAutofill(r, h) : se.call(this, !1, r, h),
        $(window, t=>{
            ({ri: r, ci: h} = i.getCellRectByXY(t.offsetX, t.offsetY)),
            l ? e.showAutofill(r, h) : 1 !== t.buttons || t.shiftKey || se.call(this, !0, r, h)
        }
        , ()=>{
            l && (i.autofill(e.arange, "all"),
            s.render()),
            e.hideAutofill(),
            function() {
                const {toolbar: t} = this;
                t.paintformatActive() && (de.call(this, "format"),
                oe.call(this),
                t.paintformatToggle())
            }
            .call(this)
        }
        )),
        l || 1 !== t.buttons || t.shiftKey && se.call(this, !0, r, h)
    }
    function ue() {
        const {editor: t, data: e} = this
          , i = e.getSelectedRect()
          , s = this.getTableOffset();
        let l = "top";
        i.top > s.height / 2 && (l = "bottom"),
        t.setOffset(i, l)
    }
    function ge() {
        const {editor: t, data: e} = this;
        ue.call(this),
        t.setCell(e.getSelectedCell()),
        oe.call(this)
    }
    function pe(t, e="finished") {
        const {data: i, table: s} = this;
        i.setSelectedCellText(t, e),
        s.render()
    }
    function me(t) {
        const {data: e} = this;
        "insert-row" === t ? e.insert("row") : "delete-row" === t ? e.delete("row") : "insert-column" === t ? e.insert("column") : "delete-column" === t ? e.delete("column") : "delete-cell" === t ? e.deleteCell() : "delete-cell-format" === t ? e.deleteCell("format") : "delete-cell-text" === t && e.deleteCell("text"),
        oe.call(this),
        ne.call(this)
    }
    function we() {
        const {overlayerEl: t, rowResizer: e, colResizer: i, verticalScrollbar: s, horizontalScrollbar: l, editor: r, contextMenu: h, data: n, toolbar: o} = this;
        t.on("mousemove", t=>{
            (function(t) {
                if (0 !== t.buttons)
                    return;
                if (t.target.className === `${D}-resizer-hover`)
                    return;
                const {offsetX: e, offsetY: i} = t
                  , {rowResizer: s, colResizer: l, tableEl: r, data: h} = this
                  , {rows: n, cols: o} = h;
                if (e > o.indexWidth && i > n.height)
                    return s.hide(),
                    void l.hide();
                const c = r.box()
                  , a = h.getCellRectByXY(t.offsetX, t.offsetY);
                a.ri >= 0 && -1 === a.ci ? (a.width = o.indexWidth,
                s.show(a, {
                    width: c.width
                })) : s.hide(),
                -1 === a.ri && a.ci >= 0 ? (a.height = n.height,
                l.show(a, {
                    height: c.height
                })) : l.hide()
            }
            ).call(this, t)
        }
        ).on("mousedown", t=>{
            2 === t.buttons ? n.xyInSelectedRect(t.offsetX, t.offsetY) ? h.setPosition(t.offsetX, t.offsetY) : h.hide() : 2 === t.detail ? ge.call(this) : (r.clear(),
            fe.call(this, t))
        }
        ).on("mousewheel.stop", t=>{
            (function(t) {
                const {verticalScrollbar: e, data: i} = this
                  , {top: s} = e.scroll();
                let l = t.deltaY;
                const {rows: r} = i;
                if (t.detail && (l = 40 * t.detail),
                l > 0) {
                    const t = i.scroll.ri + 1;
                    t < r.len && e.move({
                        top: s + r.getHeight(t) - 1
                    })
                } else {
                    const t = i.scroll.ri - 1;
                    t >= 0 && e.move({
                        top: 0 === t ? 0 : s - r.getHeight(t)
                    })
                }
            }
            ).call(this, t)
        }
        ),
        function(t, {move: e, end: i}) {
            let s = 0
              , l = 0;
            z(t, "touchstart", t=>{
                const {pageX: e, pageY: i} = t.touches[0];
                s = e,
                l = i
            }
            ),
            z(t, "touchmove", t=>{
                if (!e)
                    return;
                const {pageX: i, pageY: r} = t.changedTouches[0];
                O(i - s, r - l, t, e),
                s = i,
                l = r,
                t.preventDefault()
            }
            ),
            z(t, "touchend", t=>{
                if (!i)
                    return;
                const {pageX: e, pageY: r} = t.changedTouches[0];
                O(e - s, r - l, t, i)
            }
            )
        }(t.el, {
            move: (t,e)=>{
                (function(t, e) {
                    const {verticalScrollbar: i, horizontalScrollbar: s} = this
                      , {top: l} = i.scroll()
                      , {left: r} = s.scroll();
                    "left" === t || "right" === t ? s.move({
                        left: r - e
                    }) : "up" !== t && "down" !== t || i.move({
                        top: l - e
                    })
                }
                ).call(this, t, e)
            }
        }),
        o.change = ((t,e)=>(function(t, e) {
            const {data: i} = this;
            if ("undo" === t)
                this.undo();
            else if ("redo" === t)
                this.redo();
            else if ("print" === t)
                ;
            else if ("paintformat" === t)
                !0 === e ? ce.call(this) : oe.call(this);
            else if ("clearformat" === t)
                me.call(this, "delete-cell-format");
            else if ("link" === t)
                ;
            else if ("chart" === t)
                ;
            else if ("filter" === t)
                ;
            else if ("freeze" === t)
                if (e) {
                    const {ri: t, ci: e} = i.selector;
                    this.freeze(t, e)
                } else
                    this.freeze(0, 0);
            else
                i.setSelectedCellAttr(t, e),
                "formula" === t && ge.call(this),
                ne.call(this)
        }
        ).call(this, t, e)),
        e.finishedFn = ((t,e)=>{
            (function(t, e) {
                const {ri: i} = t
                  , {table: s, selector: l, data: r} = this;
                r.rows.setHeight(i, e),
                s.render(),
                l.resetAreaOffset(),
                re.call(this),
                ue.call(this)
            }
            ).call(this, t, e)
        }
        ),
        i.finishedFn = ((t,e)=>{
            (function(t, e) {
                const {ci: i} = t
                  , {table: s, selector: l, data: r} = this;
                r.cols.setWidth(i, e),
                s.render(),
                l.resetAreaOffset(),
                he.call(this),
                ue.call(this)
            }
            ).call(this, t, e)
        }
        ),
        s.moveFn = ((t,e)=>{
            (function(t) {
                const {data: e, table: i, selector: s} = this;
                e.scrolly(t, ()=>{
                    s.resetBRLAreaOffset(),
                    ue.call(this),
                    i.render()
                })
            })
            .call(this, t, e)
        }
        ),
        l.moveFn = ((t,e)=>{
            (function(t) {
                const {data: e, table: i, selector: s} = this;
                e.scrollx(t, ()=>{
                    s.resetBRTAreaOffset(),
                    ue.call(this),
                    i.render()
                })
            })
            .call(this, t, e)
        }),
        r.change = ((t,e)=>{
            pe.call(this, e, t)
        }),
        h.itemClick = (t=>{
            "copy" === t ? ce.call(this) : "cut" === t ? ae.call(this) : "paste" === t ? de.call(this, "all") : "paste-value" === t ? de.call(this, "text") : "paste-format" === t ? de.call(this, "format") : me.call(this, t)
        }),
        z(window, "resize", ()=>{
            this.reload()
        }),
        z(window, "click", e=>{
            this.focusing = t.contains(e.target)
        }),
        z(window, "keydown", t=>{
            if (!this.focusing)
                return;
            const e = t.keyCode || t.which, 
            	{key: i, ctrlKey: s, shiftKey: l, altKey: c} = t;
            if (s) {
                let i = "all";
                switch (l && (i = "text"),
                	c && (i = "format"),
                	e) {
                case 90:
                    this.undo(),
                    t.preventDefault();
                    break;
                case 89:
                    this.redo(),
                    t.preventDefault();
                    break;
                case 67:
                    ce.call(this),
                    t.preventDefault();
                    break;
                case 88:
                    ae.call(this),
                    t.preventDefault();
                    break;
                case 85:
                    o.trigger("underline"),
                    t.preventDefault();
                    break;
                case 86:
                    de.call(this, i),
                    t.preventDefault();
                    break;
                case 37:
                    le.call(this, l, "row-first"),
                    t.preventDefault();
                    break;
                case 38:
                    le.call(this, l, "col-first"),
                    t.preventDefault();
                    break;
                case 39:
                    le.call(this, l, "row-last"),
                    t.preventDefault();
                    break;
                case 40:
                    le.call(this, l, "col-last"),
                    t.preventDefault();
                    break;
                case 32:
                    se.call(this, !1, -1, n.selector.ci, !1),
                    t.preventDefault();
                    break;
                case 66:
                    o.trigger("font-bold");
                    break;
                case 73:
                    o.trigger("font-italic")
                }
            } else {
                switch (e) {
                case 32:
                    l && se.call(this, !1, n.selector.ri, -1, !1);
                    break;
                case 27:
                    h.hide(),
                    oe.call(this);
                    break;
                case 37:
                    le.call(this, l, "left"),
                    t.preventDefault();
                    break;
                case 38:
                    le.call(this, l, "up"),
                    t.preventDefault();
                    break;
                case 39:
                    le.call(this, l, "right"),
                    t.preventDefault();
                    break;
                case 40:
                    le.call(this, l, "down"),
                    t.preventDefault();
                    break;
                case 9:
                    r.clear(),
                    le.call(this, !1, l ? "left" : "right"),
                    t.preventDefault();
                    break;
                case 13:
                    r.clear(),
                    le.call(this, !1, l ? "up" : "down"),
                    t.preventDefault();
                    break;
                case 8:
                    me.call(this, "delete-cell-text"),
                    t.preventDefault()
                }
                "Delete" === i ? (me.call(this, "delete-cell-text"),
                t.preventDefault()) : e >= 65 && e <= 90 || e >= 48 && e <= 57 || e >= 96 && e <= 105 || "=" === t.key ? (pe.call(this, t.key, "input"),
                ge.call(this)) : 113 === e && ge.call(this)
            }
        }
        )
    }
    class be {
        constructor(t, e) {
            this.el = l("div", `${D}-sheet`),
            this.toolbar = new ie(e,!e.settings.showToolbar),
            t.children(this.toolbar.el, this.el),
            this.data = e,
            this.tableEl = l("canvas", `${D}-table`),
            this.rowResizer = new W(!1,e.rows.height),
            this.colResizer = new W(!0,e.cols.minWidth),
            this.verticalScrollbar = new R(!0),
            this.horizontalScrollbar = new R(!1),
            this.editor = new Z(ot,()=>this.getTableOffset(),e.rows.height),
            this.contextMenu = new et(()=>this.getTableOffset()),
            this.selector = new V(e),
            this.overlayerCEl = l("div", `${D}-overlayer-content`).children(this.editor.el, this.selector.el),
            this.overlayerEl = l("div", `${D}-overlayer`).child(this.overlayerCEl),
            this.el.children(this.tableEl, this.overlayerEl.el, this.rowResizer.el, this.colResizer.el, this.verticalScrollbar.el, this.horizontalScrollbar.el, this.contextMenu.el),
            this.table = new Dt(this.tableEl.el,e),
            we.call(this),
            ne.call(this),
            se.call(this, !1, 0, 0)
        }
        loadData(t) {
            return this.data.setData(t),
            ne.call(this),
            this
        }
        freeze(t, e) {
            const {data: i} = this;
            return i.setFreeze(t, e),
            ne.call(this),
            this
        }
        undo() {
            this.data.undo(),
            ne.call(this)
        }
        redo() {
            this.data.redo(),
            ne.call(this)
        }
        reload() {
            return ne.call(this),
            this
        }
        getRect() {
            const {data: t} = this;
            return {
                width: t.viewWidth(),
                height: t.viewHeight()
            }
        }
        getTableOffset() {
            const {rows: t, cols: e} = this.data
              , {width: i, height: s} = this.getRect();
            return {
                width: i - e.indexWidth,
                height: s - t.height,
                left: e.indexWidth,
                top: t.height
            }
        }
    }
    i(0);
    i.d(e, "spreadsheet", function() {
        return ve
    });
    class ye {
        constructor(t, e={}) {
            let i = t;
            "string" == typeof t && (i = document.querySelector(t)),
            this.data = new S("sheet1",e);
            const s = l("div", `${D}`).on("contextmenu", t=>t.preventDefault());
            i.appendChild(s.el),
            this.sheet = new be(s,this.data)
        }
        loadData(t) {
            return this.sheet.loadData(t),
            this
        }
        getData() {
            return this.data.getData()
        }
        change(t) {
            return this.data.change = t,
            this
        }
    }
    const ve = (t,e={})=>new ye(t,e);
    window && (window.x = window.x || {},
    window.x.spreadsheet = ve);
    e.default = ye
}
]);
